/    Sign up×
Community /Pin to ProfileBookmark

crossbrowser CSS drop menu

I am trying to create a simple horizontal CSS crossbrowser drop menu. In theory, the code should work [I][B]in IE6 as well[/B][/I], but it does not. What could be wrong?

[code]
<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01//EN” “http://www.w3.org/TR/html4/strict.dtd”>
<html>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
<title>Untitled Document</title>
<style type=”text/css”>
html body{
margin:0;
padding:0;
}
.menu {
width:300px;
margin:20px auto 0 auto;
}
.menu ul{
margin:0;
padding:0;
list-style-type:none;
}
.menu ul a{
display:block;
background:#ccc;
width:150px;
height:20px;
}
.menu li{
float:left;
width:150px;
position:relative;
}
.menu ul ul{
position:absolute;
visibility:hidden;
}
.menu ul li:hover ul, .menu ul a:hover ul{
visibility:visible;
}
/* IE6 hacks */
.menu table{
position:absolute;
border-collapse:collapse;
top:0;
left:0;
margin:0;
}
* html .menu ul ul {
top:20px;
}
</style>
</head>
<body>
<div class=”menu”>
<ul>
<li>
<a href=”#”>link 1<!–[if IE 7]><!–></a><!–<![endif]–>
<!–[if lte IE 6]><table><tr><td><![endif]–>
<ul>
<li><a href=”#”>sublink 1.1</a></li>
<li><a href=”#”>sublink 1.2</a></li>
</ul>
<!–[if lte IE 6]></td></tr></table></a><![endif]–>
</li>
<li>
<a href=”#”>link 2<!–[if IE 7]><!–></a><!–<![endif]–>
<!–[if lte IE 6]><table><tr><td><![endif]–>
<ul>
<li><a href=”#”>sublink 2.1</a></li>
<li><a href=”#”>sublink 2.2</a></li>
<li><a href=”#”>sublink 2.3</a></li>
</ul>
<!–[if lte IE 6]></td></tr></table></a><![endif]–>
</li>
</ul>
</div>
</body>
</html>
[/code]

Any ideas or other approaches?

to post a comment
CSS

3 Comments(s)

Copy linkTweet thisAlerts:
@JickDec 15.2008 — The reason it does not work in IE6 is because IE6 does not support the :hover pseudo class on arbitrary elements. It only supports it on link elements [I]([FONT="Courier New"]<a>[/FONT])[/I]. This article covers the issue and also talks about a workaround.

Hope that helps. ?
Copy linkTweet thisAlerts:
@KorauthorDec 16.2008 — Thank you for the answer.

I know that IE6 supports :hover pseudoclasses only on links, but I have tried to overpass that by using [COLOR="Blue"]a descendant rule [/COLOR]
<i>
</i>[COLOR="DarkGreen"].menu ul li:hover ul[/COLOR], [COLOR="Blue"].menu ul a:hover ul[/COLOR]{
visibility:visible;
}

and the IE6 CSS and HTML[COLOR="DimGray"] [if lte IE 6][/COLOR] hacks below

Thank you very much for the article, as well. At a first glance, the article speaks about the same I have already done (a descendant rule), but I will read it more attentively to see what is the difference.
Copy linkTweet thisAlerts:
@JickDec 16.2008 — I know that IE6 supports :hover pseudoclasses only on links, but I have tried to overpass that by using [COLOR="Blue"]a descendant rule [/COLOR]
<i>
</i>[COLOR="DarkGreen"].menu ul li:hover ul[/COLOR], [COLOR="Blue"].menu ul a:hover ul[/COLOR]{
visibility:visible;
}

and the IE6 CSS and HTML[COLOR="DimGray"] [if lte IE 6][/COLOR] hacks below[/QUOTE]
My best guess would be that IE isn't going for what you're trying. Not that far-fetched considering IE doesn't go for a lot of things. :p

Thank you very much for the article, as well. At a first glance, the article speaks about the same I have already done (a descendant rule), but I will read it more attentively to see what is the difference.[/QUOTE]Well, that article may not be what you need. It's just something I found on a quick search of Google.

Perhaps someone else will come along with a better answer...
×

Success!

Help @Kor spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...