473,395 Members | 1,938 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,395 software developers and data experts.

CSS Dropdown Menus: Firefox vs IE7 positioning

I have developed a generic list-based css menu. It works both in IE7 and
Firefox, and with the help of Peter Nederlof's csshover.htc, with older
IE versions.

I have included a simplified version below. The list goes something like
this:

<ul class="menu">
<li>Menu 1
<ul> <li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>Menu 2
<ul> <li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
</ul>

The question is this: my style for the nested ul includes
position: absolute;

Firefox positions the ul below the li, while IE7 positions it to its
right. Using position: relative positions them both correctly, but
destroys the menu effect.

Is there a trick to getting IE7 to position the ul below the li?

Below is the code I am using.

Thanks

Mark

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Menu</title>
<style type="text/css">
/* Essential */
.break { clear: left; }
.menu li { display: block; /* FireFox */ float: left; }
.menu li ul { position: absolute; display: none; }
.menu li ul li { float: none; display: block; }
.menu li:hover ul { display: block; }
.menu a { display: block; /* Firefox Only */ }
/* Visual */
.menu li {
background-color: lightblue;
padding: 4px;
border: solid 1px;
font-family: sans-serif;
}
.menu li ul {
padding-left: 0px; /* FireFox */
margin-left: 0px; /* IE */
border: solid 1px;
margin: 4px 0px 0px -5px;
}
.menu li ul li {
padding: 0px; border: 0px;
}
.menu li:hover {
background-color: pink;
}
.menu a {
text-decoration: none;
}
</style>
</head>
<body>
<h1 class="intro">Menu</h1>
<ul class="menu">
<li>JavaScript
<ul><li><a href="#">Web Developers Notes</a></li>
<li><a href="#">DevGuru</a></li>
<li><a href="#">QuirksMode</a></li>
<li><a href="#">World Wide Web Consortium</a></li>
<li><a href="#">XML.com</a></li>
<li><a href="#">W3Schools</a></li>
<li><a href="#">How to Create</a></li>
<li><a href="#">Mozilla: Using Web Standards</a></li>
<li><a href="#">JavaScript Kit</a></li>
</ul>
</li>
<li>Browsers
<ul><li><a href="#">Mozilla Firefox</a></li>
<li><a href="#">NetScape</a></li>
<li><a href="#">Opera</a></li>
<li><a href="#">Apple Safari</a></li>
<li><a href="#">Old Internet Explorer</a></li>
</ul>
</li>
</ul>
<div class="break">etc etc etc etc etc</div>
</body>
</html>
Jan 23 '07 #1
4 8792
On 2007-01-23, Mark <ma**@comparity.not.example.netwrote:
I have developed a generic list-based css menu. It works both in IE7 and
Firefox, and with the help of Peter Nederlof's csshover.htc, with older
IE versions.
[snip]
The question is this: my style for the nested ul includes
position: absolute;

Firefox positions the ul below the li, while IE7 positions it to its
right. Using position: relative positions them both correctly, but
destroys the menu effect.

Is there a trick to getting IE7 to position the ul below the li?
You're relying on the computed "static" values of top and left for
absolutely positioned elements-- the browser is supposed to put them
roughly where they would have gone had they not been positioned, but is
free to make a guess at that position.

You should get more consistent results if you set top and left on .menu
li ul. Setting .menu to position: relative will make those top and left
positions relative to .menu rather than to the viewport, which will
probably be more helpful.
Jan 23 '07 #2
Hi, Mark

You can quickly fix your meny by adding <div
style="position:relative">. This <divwill establish container-block
for the descendant absolutelly postioned <ul>.
(http://www.w3.org/TR/2005/WD-CSS21-2...suren.html#q28)

= = = = = =
<li>JavaScript
<div style="position:relative">
<ul><li><a href="#">Web Developers Notes</a></li>
<li><a href="#">DevGuru</a></li>
...
</ul>
</div>
</li>
= = = = = =

- Alex.

P.S. But your menu does not work under IE6 due to the lack of li:hover
support.

Jan 23 '07 #3
Thanks, Ben and (forgroupsonly) for your comments.

I did find an alternative method, which is not quite as pure as I would
have liked, but it works:

I have include a <br/after each menu:

<ul class="menu">
<li>Menu 1<br/>
<ul><li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>Menu 2<br/>
<ul><li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
</ul>

I then use the visibility instead of the display attribute:

.menu li ul { position: absolute; visibility: hidden; }
.menu li:hover ul { visibility: visible; }

That seems to do the trick.

I haven't tested my fixed version on IE6, but I know that the unfixed
version worked, as long as I included csshover.htc

Thanks,

Mark

Mark wrote:
I have developed a generic list-based css menu. It works both in IE7 and
Firefox, and with the help of Peter Nederlof's csshover.htc, with older
IE versions.

I have included a simplified version below. The list goes something like
this:

<ul class="menu">
<li>Menu 1
<ul <li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>Menu 2
<ul <li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
</ul>

The question is this: my style for the nested ul includes
position: absolute;

Firefox positions the ul below the li, while IE7 positions it to its
right. Using position: relative positions them both correctly, but
destroys the menu effect.

Is there a trick to getting IE7 to position the ul below the li?

Below is the code I am using.

Thanks

Mark

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Menu</title>
<style type="text/css">
/* Essential */
.break { clear: left; }
.menu li { display: block; /* FireFox */ float: left; }
.menu li ul { position: absolute; display: none; }
.menu li ul li { float: none; display: block; }
.menu li:hover ul { display: block; }
.menu a { display: block; /* Firefox Only */ }
/* Visual */
.menu li {
background-color: lightblue;
padding: 4px;
border: solid 1px;
font-family: sans-serif;
}
.menu li ul {
padding-left: 0px; /* FireFox */
margin-left: 0px; /* IE */
border: solid 1px;
margin: 4px 0px 0px -5px;
}
.menu li ul li {
padding: 0px; border: 0px;
}
.menu li:hover {
background-color: pink;
}
.menu a {
text-decoration: none;
}
</style>
</head>
<body>
<h1 class="intro">Menu</h1>
<ul class="menu">
<li>JavaScript
<ul><li><a href="#">Web Developers Notes</a></li>
<li><a href="#">DevGuru</a></li>
<li><a href="#">QuirksMode</a></li>
<li><a href="#">World Wide Web Consortium</a></li>
<li><a href="#">XML.com</a></li>
<li><a href="#">W3Schools</a></li>
<li><a href="#">How to Create</a></li>
<li><a href="#">Mozilla: Using Web Standards</a></li>
<li><a href="#">JavaScript Kit</a></li>
</ul>
</li>
<li>Browsers
<ul><li><a href="#">Mozilla Firefox</a></li>
<li><a href="#">NetScape</a></li>
<li><a href="#">Opera</a></li>
<li><a href="#">Apple Safari</a></li>
<li><a href="#">Old Internet Explorer</a></li>
</ul>
</li>
</ul>
<div class="break">etc etc etc etc etc</div>
</body>
</html>
Jan 24 '07 #4
Mark wrote :
I have developed a generic list-based css menu. It works both in IE7 and
Firefox, and with the help of Peter Nederlof's csshover.htc, with older
IE versions.

I have included a simplified version below. The list goes something like
this:

<ul class="menu">
<li>Menu 1
<ul <li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
<li>Menu 2
<ul <li>Item 1</li>
<li>Item 2</li>
<li>Item 3</li>
</ul>
</li>
</ul>

The question is this: my style for the nested ul includes
position: absolute;

Firefox positions the ul below the li, while IE7 positions it to its
right.
MSIE7 has defined, clearly documented and well reported bugs on its
collapse adjoining margins algorithm:
http://www.gtalbot.org/BrowserBugsSection/MSIE7Bugs/

Using position: relative positions them both correctly, but
destroys the menu effect.

Is there a trick to getting IE7 to position the ul below the li?

Below is the code I am using.
Please always post an url, not code.
>
Thanks

Mark

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Menu</title>
<style type="text/css">
/* Essential */
.break { clear: left; }
.menu li { display: block; /* FireFox */ float: left; }
Why display: block? If you want to set list-item as block, then use
<div>s instead of redefining list-item. If you want to remove the
list-item bullet, then use
ul {list-style-type: none;}
which is better. The nested lists structure will degrade more gracefully
in non-css-capable browsers and in buggy browsers.
.menu li ul { position: absolute; display: none; }
.menu li ul li { float: none; display: block; }
Here too: why not just declare only once
ul {list-style-type: none;}
and then remove that display: block for list-items.
.menu li:hover ul { display: block; }
.menu a { display: block; /* Firefox Only */ }
Here too: unneeded css rule.
/* Visual */
.menu li {
background-color: lightblue;
padding: 4px;
border: solid 1px;
font-family: sans-serif;
}
.menu li ul {
padding-left: 0px; /* FireFox */
margin-left: 0px; /* IE */
border: solid 1px;
margin: 4px 0px 0px -5px;
You already defined margin-left: 0px and here, you are redefining that
property to -5px. So, the declaration
margin-left: 0px;
was unneeded.

Gérard
--
remove blah to email me
Jan 25 '07 #5

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

Similar topics

19
by: chart43 | last post by:
I have question about the technique for css dropdown menus described in http://www.alistapart.com/articles/horizdropdowns/. Based on an html list, it has a few items in a 1st order list and further...
18
by: sandy | last post by:
This sounds like a frequently asked question, but I didn't find the answer in any faq I've looked at. I have a question about the wisdom of using (javascript generated) dropdown menus. ...
14
by: axlq | last post by:
I am trying to figure out what is the minimal simplest CSS I can have to accomplish a row of tabs, with one or more tabs having a drop-down menu when you hover over it -- AND the whole tab+menu...
6
by: nishac | last post by:
Can anyone suggest me how to make my drop down menu work in IE7 too.Its working in other browsers.On mouse over the submenus should be displayed.Am attaching my css code hereby.Anyone please check...
2
by: Tom | last post by:
I have taken over admin of a web site (I'm not a web developer by trade) and the drop down menus are inoperative. There is Javascript that was written about 6 or 7 years ago that have some...
4
torquehero
by: torquehero | last post by:
Hi all :) I have created a horizontal navbar using Xara Menumaker. The Menu items have several dropdown menus. Its a javascript. When the mouse cursor is moved over any menu item, a dropdown...
1
by: pedalpete | last post by:
Hey Gang, More difficult to describe this than see it, so here's a link which shows the issue I'm having http://zifimusic.com/testing/broken-hovers.html I've been looking at this for quite a...
19
by: Jim | last post by:
Hi, I have two questions/problems pertaining to CSS horizontal dropdown menus and am hoping that someone here can help me out. (1) I'm having a problem centering the menu. I picked up the...
41
by: Stan Brown | last post by:
As usual, it looks right in Firefox 3 but not in IE6. See http://www.tc3.edu/instruct/sbrown/nicholls/indexgood.htm for the desired behavior -- when you hover over the second or third main menu...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
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,...
0
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...
0
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,...

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.