Forum Moderators: not2easy

Message Too Old, No Replies

Horizontal list nav and subnav - is it possible?

Horizontal ul with nested ul below without absolute positioning

         

Kat_Smith

3:28 pm on Apr 17, 2009 (gmt 0)

10+ Year Member



I'm creating a HTML/CSS page which has main nav as a horizontal tabbed ul with subnav as a horizontal ul below. See here for example:
<snip>

The subnav is absolutely positioned in order to appear below the main nav HOWEVER a new requirement for this site is for text size to increase by 4 times (e.g. in FF text zoom only, CTRL and + four times). The problem is that when the text is very large, it wraps the main nav tabs below the absolutely positioned subnav and becomes obscured.

I can't see any way around this - is is possible? If the subnav ul is not absolutely positioned, it breaks the main nav ul. Is there any way for a ul nested inside a li to sit below the main ul, without using absolute positioning?

The relevant parts of the CSS, with all other styling removed, are:

#hdr_links {
clear: both;
width: 955px;
}

#hdr_links ul li ul {
position: absolute;
top: 175px;
left: 0px;
height: 31px;
width: 955px;
}

#hdr_links ul, #hdr_links ul li ul {
list-style-type: none;
}

#hdr_links li {
float: left;
}

#hdr_links li ul li {
float: left;
height: 30px;
}

[edited by: swa66 at 7:39 pm (utc) on April 17, 2009]
[edit reason] No personal URLs allowed please see ToS and forum charter [/edit]

mihai2u

11:05 am on Apr 18, 2009 (gmt 0)

10+ Year Member



First of all relative position your first level ul
#hdr_links ul {position:relative;}

And now you absolute position your 2nd level ul with respect to the main 1st level nav.

Second step is to set the height of the 1st level nav in em.
#hrd_links li {height:1em;}

and update the positioning of the 2nd level ul - to use esm instead of pixels
#hrd_links ul ul {top:1em;} // instead of 175px
or whatever is the em height of your 1st level links.

This would "move" the 2nd level nav when the font size is increased.

P.S. Make sure to use ems for the font-sizes as well, as they won't change their size in IE.

Kat_Smith

10:42 am on Apr 20, 2009 (gmt 0)

10+ Year Member



Thanks very much for your reply. I have stripped down the code to the bare bones and applied the CSS you suggested. It works in IE (in the bare bones version at least) but I get the same problem in FF3 i.e. the main menu wraps below the sub menu after a couple of text size increases. Any suggestions or ideas?

The code I'm using is:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<style>
#hdr_links {
width: 955px;
}
#hdr_links ul {
list-style-type: none;
position:relative;
width: 955px;
}
#hdr_links li {
height:2.5em;
float: left;
padding: 10px;
}
#hdr_links ul li ul {
list-style-type: none;
position: absolute;
top: 3em;
left: 0em;
color: #000;
background-color: #f00;
}
#hdr_links li ul li {
float: left;
}
</style>
</head>
<body>
<div id="hdr_links">
<ul>
<li>Home</li><li>Our products<ul><li>Product menu&nbsp; &nbsp;¦</li><li>Which product is best for you?&nbsp; &nbsp;¦</li><li>Full Investment Fund</li></ul></li><li>How to apply</li><li>Our investments</li><li>News &amp; events</li>
<li>About us</li><li>Contact us</li>
</ul>
</div>
</body>
</html>

swa66

4:10 am on Apr 21, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<ul> and/or <li> have default padding or margins (I always forget what in which browser) and its not the same in all browsers. You need to reset both.

It feels like you're unaware that what you apply to e.g. #hdr_links li get applied to all <li>s (of whatever nesting) inside any element with that id. So it also applies to "#hdr_links li ul li". If you want to have something nly appled to the first level you either
- need to use a selector like #hdr_links>ul>li (But IE6 will give you grief)
- need to counteract all settings in a the more specific rule (and there's no need there then to repeat what's already there.

Finally legacy IE versions and FF disagreeing over a layout: it's virtually always going to be IE that's wrong.

Start by making sure the code is valid (your html has issues).

But, to be honest I don't see a problem of wrapping when I zoom in in FF3 (mac latest version) All the way zoomed out to all the way zoomed in it's the same except for size and creating a scroll bar if it gets too wide.

I'd also ditch the div and place the id on the ul, much simpler.