473,378 Members | 1,489 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

html/span/css navbar hell

Hello,

I'm trying to implement a navigation bar with a ul in css. The code is
a template, but i'm customizing. I can handle just text in each block,
but i want the first block to have an image and then text, which I'm
doing with a span element. I think i need it that way to handle text
positioning of the text.

So there's an anchor block, and inside4 that i'm putting an image and
a span block.
Except. It. Doesn't. Work. http://www.discovertheuser.com/images/img1.gif
You can see the span sticking out of its ancestor blocks, and the text
padding screwed up. And some of the anchor block padding is stretching
below the img. I can get the span to show up below the img if i float
it left, and if I take my vertical-align to bottom, the span shows up
above the ul block.

I think there's some funky block/block/span quirkiness going on, and
I'd appreciate it if someone could steer me toward an explanation.
Thanks in advance for your help :).

The html:
<ul id="nav">
<li id="nav-home"><a id="a-home" href="../index.html"><img id="navimg"
src="../images/photos/dj.jpg" width="90" height="70" border="0"><span
class="regular">Home</span></a></li>

The css:
#nav {
margin-left:10%;
margin-right:10%;
margin-top:0;
margin-bottom:0;
padding:0;
background:#7A95FF url(nav_bg.jpg) 0 0 repeat-x;
float:left;
width:100%;
border:1px solid #000000;
border-width:1px 1px 2px 1px;
}
#nav li{
display:inline;
padding:0;
margin:0;
vertical-align:text-bottom;
}

#nav a:link,
#nav a:visited{
float:left;
color:#000;
background:#FFCC00;
padding:40px 40px 4px 10px;
width:auto;
height:25px;
border-right:1px solid #42432d;
text-decoration:none;
font:bold 1em/1em Arial, Helvetica, sans-serif;
text-transform:uppercase;
text-shadow: 2px 2px 2px #555;

}

#nav #a-home{
display:inline-block;
padding-top:0px;
padding-right:0px;
margin-bottom:0px;
height:auto;
padding-left:4px;
padding-bottom:0px;
}

#nav img{
margin:0px !important;
}

.regular{
float:none !important;
background-color:blue !important;
padding:40px 40px 4px 10px !important;
margin:0px !important;
height:25px !important;
}

Feb 8 '07 #1
5 5475
On 2007-02-08, David Housman <dh******@gmail.comwrote:
Hello,

I'm trying to implement a navigation bar with a ul in css. The code is
a template, but i'm customizing. I can handle just text in each block,
but i want the first block to have an image and then text, which I'm
doing with a span element. I think i need it that way to handle text
positioning of the text.

So there's an anchor block, and inside4 that i'm putting an image and
a span block.
Except. It. Doesn't. Work. http://www.discovertheuser.com/images/img1.gif
You can see the span sticking out of its ancestor blocks, and the text
padding screwed up. And some of the anchor block padding is stretching
below the img.
I can get the span to show up below the img if i float
it left, and if I take my vertical-align to bottom, the span shows up
above the ul block.
Do you want the span below the image, or to the right of it?
I think there's some funky block/block/span quirkiness going on, and
I'd appreciate it if someone could steer me toward an explanation.
..regular is an inline box. The exact dimensions of its background box is
not defined by the spec, and in this case, it extends below the
characters of "Home" to make room for the descenders in the current
font. If you look closely at your gif image, you will see that the
bottom of the image is aligned with the baseline of the text.

Basically I would say setting backgrounds, borders etc. on inline boxes
is not going to be a good way to do toolbars like this. Save it for
highlighting portions of text in a paragraph and things like that.

You need to work with block boxes and probably floats since inline-block
is not well supported.
The css:
#nav {
margin-left:10%;
margin-right:10%;
margin-top:0;
margin-bottom:0;
padding:0;
background:#7A95FF url(nav_bg.jpg) 0 0 repeat-x;
float:left;
width:100%;
margin-left:10% and width:100% means a horizontal scrollbar is
inevitable. Does #nav need to be floated?

[...]
#nav #a-home{
display:inline-block;
I can't see much reason for display: inline-block here, and it isn't
supported in Firefox.
Feb 8 '07 #2
Hi,
Thanks for your help. Your advice has been helpful in helping me
understand what is going on. I"m not sure if my reply didn't get
through or was moderated, but I'll be more concise. and hope it was
teh former.
I have text inside a span inside an anchor. While I set teh box
attributes of the span
.regular{
float:none !important;
background-color:blue !important;
padding:40px 40px 4px 10px !important;
margin:0px 0px 10px 0px !important;
height:25px !important;
}

the text is potitioned at the baseline of the anchor (orangish)
element, (http://www.discovertheuser.com/images/img1.gif) and I can't
figure out why. Isn't the box around the text determined by the
attributes of the span? Why does the baseline of the text have any
bearing on the position of the span or teh text within the span?

Another question: Should the #nav box stretch to contain its objects,
if its set to height:auto? In the picture, its float:left. If i make
it float:none, the height collapses, I can make it big enough with a
div clear element or by manually setting the height. I would have
thought that if on auto, a containing block would stretch to fit its
child objects? Why does float have an effect on this?

Thanks,
Dave

\ ApparWhy does the position of the text matter from the perspective
of the enclosing anch
On Feb 8, 12:27 am, Ben C <spams...@spam.eggswrote:
On 2007-02-08, David Housman <dhous...@gmail.comwrote:
Hello,
I'm trying to implement a navigation bar with a ul in css. The code is
a template, but i'm customizing. I can handle just text in each block,
but i want the first block to have an image and then text, which I'm
doing with a span element. I think i need it that way to handle text
positioning of the text.
So there's an anchor block, and inside4 that i'm putting an image and
a span block.
Except. It. Doesn't. Work.http://www.discovertheuser.com/images/img1.gif
You can see the span sticking out of its ancestor blocks, and the text
padding screwed up. And some of the anchor block padding is stretching
below the img.
I can get the span to show up below the img if i float
it left, and if I take my vertical-align to bottom, the span shows up
above the ul block.

Do you want the span below the image, or to the right of it?
I think there's some funky block/block/span quirkiness going on, and
I'd appreciate it if someone could steer me toward an explanation.

.regular is an inline box. The exact dimensions of its background box is
not defined by the spec, and in this case, it extends below the
characters of "Home" to make room for the descenders in the current
font. If you look closely at your gif image, you will see that the
bottom of the image is aligned with the baseline of the text.

Basically I would say setting backgrounds, borders etc. on inline boxes
is not going to be a good way to do toolbars like this. Save it for
highlighting portions of text in a paragraph and things like that.

You need to work with block boxes and probably floats since inline-block
is not well supported.
The css:
#nav {
margin-left:10%;
margin-right:10%;
margin-top:0;
margin-bottom:0;
padding:0;
background:#7A95FF url(nav_bg.jpg) 0 0 repeat-x;
float:left;
width:100%;

margin-left:10% and width:100% means a horizontal scrollbar is
inevitable. Does #nav need to be floated?

[...]
#nav #a-home{
display:inline-block;

I can't see much reason for display: inline-block here, and it isn't
supported in Firefox.

Feb 9 '07 #3
Almost forgot: I'm trying to put teh text to the right of the image.

Thanks again,
Dave
On Feb 9, 2:19 pm, "David Housman" <dhous...@gmail.comwrote:
Hi,
Thanks for your help. Your advice has been helpful in helping me
understand what is going on. I"m not sure if my reply didn't get
through or was moderated, but I'll be more concise. and hope it was
teh former.
I have text inside a span inside an anchor. While I set teh box
attributes of the span
.regular{
float:none !important;
background-color:blue !important;
padding:40px 40px 4px 10px !important;
margin:0px 0px 10px 0px !important;
height:25px !important;

}

the text is potitioned at the baseline of the anchor (orangish)
element, (http://www.discovertheuser.com/images/img1.gif) and I can't
figure out why. Isn't the box around the text determined by the
attributes of the span? Why does the baseline of the text have any
bearing on the position of the span or teh text within the span?

Another question: Should the #nav box stretch to contain its objects,
if its set to height:auto? In the picture, its float:left. If i make
it float:none, the height collapses, I can make it big enough with a
div clear element or by manually setting the height. I would have
thought that if on auto, a containing block would stretch to fit its
child objects? Why does float have an effect on this?

Thanks,
Dave

\ ApparWhy does the position of the text matter from the perspective
of the enclosing anch
On Feb 8, 12:27 am, Ben C <spams...@spam.eggswrote:
On 2007-02-08, David Housman <dhous...@gmail.comwrote:
Hello,
I'm trying to implement a navigation bar with a ul in css. The code is
a template, but i'm customizing. I can handle just text in each block,
but i want the first block to have an image and then text, which I'm
doing with a span element. I think i need it that way to handle text
positioning of the text.
So there's an anchor block, and inside4 that i'm putting an image and
a span block.
Except. It. Doesn't. Work.http://www.discovertheuser.com/images/img1.gif
You can see the span sticking out of its ancestor blocks, and the text
padding screwed up. And some of the anchor block padding is stretching
below the img.
I can get the span to show up below the img if i float
it left, and if I take my vertical-align to bottom, the span shows up
above the ul block.
Do you want the span below the image, or to the right of it?
I think there's some funky block/block/span quirkiness going on, and
I'd appreciate it if someone could steer me toward an explanation.
.regular is an inline box. The exact dimensions of its background box is
not defined by the spec, and in this case, it extends below the
characters of "Home" to make room for the descenders in the current
font. If you look closely at your gif image, you will see that the
bottom of the image is aligned with the baseline of the text.
Basically I would say setting backgrounds, borders etc. on inline boxes
is not going to be a good way to do toolbars like this. Save it for
highlighting portions of text in a paragraph and things like that.
You need to work with block boxes and probably floats since inline-block
is not well supported.
The css:
#nav {
margin-left:10%;
margin-right:10%;
margin-top:0;
margin-bottom:0;
padding:0;
background:#7A95FF url(nav_bg.jpg) 0 0 repeat-x;
float:left;
width:100%;
margin-left:10% and width:100% means a horizontal scrollbar is
inevitable. Does #nav need to be floated?
[...]
#nav #a-home{
display:inline-block;
I can't see much reason for display: inline-block here, and it isn't
supported in Firefox.

Feb 9 '07 #4
On 2007-02-09, David Housman <dh******@gmail.comwrote:
Hi,
Thanks for your help. Your advice has been helpful in helping me
understand what is going on. I"m not sure if my reply didn't get
through or was moderated, but I'll be more concise. and hope it was
teh former.
I don't think this NG is moderated, so it would have been the former.
I have text inside a span inside an anchor. While I set teh box
attributes of the span
.regular{
float:none !important;
background-color:blue !important;
padding:40px 40px 4px 10px !important;
margin:0px 0px 10px 0px !important;
height:25px !important;
}

the text is potitioned at the baseline of the anchor (orangish)
element, (http://www.discovertheuser.com/images/img1.gif) and I can't
figure out why.
Isn't the box around the text determined by the
attributes of the span? Why does the baseline of the text have any
bearing on the position of the span or teh text within the span?
The text sits on the baseline. Setting background colour on the inline
box is like painting some decoration around and behind the text. The
positioning is still determined by how the text sits on the line.
Another question: Should the #nav box stretch to contain its objects,
if its set to height:auto? In the picture, its float:left. If i make
it float:none, the height collapses, I can make it big enough with a
div clear element or by manually setting the height. I would have
thought that if on auto, a containing block would stretch to fit its
child objects? Why does float have an effect on this?
Basically because the rules say so. A float, absolutely positioned
element, inline-block, table-cell, or an element with 'overflow' other
than 'visible' establishes a new "block formatting context", which means
that it grows vertically to fit floats in. Normal boxes don't. If you
float #nav it starts a new block formatting context.

I think (in the absence of inline-block) you're better off making
everything a float. It is possible to use inline boxes and
vertical-align for this, but then it's hard to do the separators between
the boxes (the black vertical borders between "HOME", "ABOUT", etc.).

Here is an example, not perfect I'm sure but might give you some ideas.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/REC-html40/strict.dtd">
<html>
<head>
<title>Test Page</title>
<style type="text/css">
div#nav
{
border: 2px solid black;
height: 100px;
}
div#nav .label
{
float: left;
background-color: yellow;
border-right: 1px solid black;
border-left: 1px solid black;
}
div#nav span.label
{
text-transform: uppercase;
padding: 40px 40px 4px 10px;
height: 56px; /* 100 - 44 */
}
div#nav img.label
{
height: 100px;
}
</style>
</head>
<body>
<div id="nav">
<img class="label" src="foo.png">
<span class="label">Home</span>
<span class="label">About</span>
<span class="label">Portfolio</span>
</div>
</body>
</html>
Feb 10 '07 #5
Ben C wrote:
On 2007-02-09, David Housman <dh******@gmail.comwrote:
>Should the #nav box stretch to contain its objects,
if its set to height:auto? In the picture, its float:left. If i make
it float:none, the height collapses,

A float, absolutely positioned
element, inline-block, table-cell, or an element with 'overflow' other
than 'visible' establishes a new "block formatting context", which means
that it grows vertically to fit floats in. Normal boxes don't.
The difference here is block vs inline content. The height property
doesn't apply to non-replaced inline elements, which includes span.
Floated elements automatically become block.
http://www.w3.org/TR/CSS21/visudet.html#propdef-height
http://www.w3.org/TR/CSS21/visuren.html#float-position
<div id="nav">
<img class="label" src="foo.png">
<span class="label">Home</span>
<span class="label">About</span>
<span class="label">Portfolio</span>
</div>
See http://css.maxdesign.com.au/listamatic/

--
Berg
Feb 10 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: rick | last post by:
Hello everyone I am trying to locate the sample files used in "A tour of the code - NavBar" for the redesign of the msdn online website in 1998. They were written and developed by Robert Carter...
13
by: TinyTim | last post by:
I'm a newbie at ASP & HTML. It seems that when you use server side code and you're going to return a customized HTML form with several fields and labels, you have to do an extensive amount of...
2
by: deko | last post by:
I use variables in some links on my page. I need to send these variables so I can change the color of the links in the navbar when the user is on that page. If you click around on the site you...
2
by: KathyB | last post by:
Hi, I have the following script in an aspx html: <script language="javascript"> function pop_window() { var confirmWin = null; confirmWin = window.open('Scanned.aspx', 'SerialNumbers',...
2
by: dartanian | last post by:
I have a fluid horizontal navbar on my website which is formatted using floats and percentage widths to make it fluid. This looks great in WinXP Firefox, Opera, and even IE6. Safari and IE7 render...
4
by: ZigZak | last post by:
At the risk of infuriating you guys, I was wondering why this code displays differently in IE and Firefox.. I have an idea, but I'm not sure why this code keeps removing the ! when I try to save...
7
by: imtmub | last post by:
I have a page, Head tag Contains many Scripts and style sheet for Menu and Page. This code working fine and displaying menus and page as i wanted. Check this page for reference....
7
by: JackRbt | last post by:
I have a navbar in a div, with several links. The last one is in a <span> because I want it to float to the right by itself. The span does float right, but it shows up below the navbar div. I want it...
0
by: studentofknowledge | last post by:
hi my knowledgeable comrads I have created a web form using html, css with the addition of some basic javascript validation. Although now im having trouble to insert this information to my local...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.