473,657 Members | 2,479 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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"><im g id="navimg"
src="../images/photos/dj.jpg" width="90" height="70" border="0"><spa n
class="regular" >Home</span></a></li>

The css:
#nav {
margin-left:10%;
margin-right:10%;
margin-top:0;
margin-bottom:0;
padding:0;
background:#7A9 5FF 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:#FFC C00;
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:upper case;
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 5482
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:#7A9 5FF 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:#7A9 5FF 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:#7A9 5FF 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">H ome</span>
<span class="label">A bout</span>
<span class="label">P ortfolio</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">H ome</span>
<span class="label">A bout</span>
<span class="label">P ortfolio</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
1469
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 and George Young and consist of several include files and css files, prepared for ASP. I located the documents in the MSDN Library Archive and this is very, very close to what I would like to do for our own website. The link for the sample downloads...
13
4734
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 Response.Writes. Are there any tools that will let you design the form then convert that form to Response.Writes that you can further customize with ASP logic? For instance: use Dreamweaver to design the form, then another program to convert to...
2
5908
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 will see the links in the navbar change: http://www.clearpointsystems.com/ When I try to validate the page at http://validator.w3.org/ I get the following error:
2
4337
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', 'width=300,height=400,left=200,top=200,toolbar=no,resizable=no,menubar=no'); } </script>
2
2542
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 it incorrectly. I've tried playing with the ul, li, a css but can't get this to look right in the latter 2 browsers. The site is sinaiem.org . Any insight would be much appreciated. Thanks. Relevant css: #navbar { /* horizontal navbar...
4
1386
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 it : <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"> Also, I've tried putting # in front of the...
7
3604
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. http://www.marco.com.cn/web-content/marco_re10.html -------------------------------------------------------------- <head> <!-- InstanceBeginEditable name="doctitle" --> <title>Marco</title> <!-- InstanceEndEditable -->
7
25829
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 within the div. Is this doable? Thanks. <?php echo "<p>"; echo '<div id="navbar"> <a href="edit_reg.php">edit</a> &nbsp;<a href="undelete.php">undelete</a>
0
7134
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 SQL database - can someone point me in the right direction please or refer me to a good example/pre written code? I am using Vista Business operating system in conjunction with SQL server 2005 express edition, SQL server service pack 2, SQL server...
0
8325
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8844
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8742
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8518
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8621
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7354
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6177
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5643
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
2
1734
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.