/    Sign up×
Community /Pin to ProfileBookmark

Nested unordered lists compatibility issues in IE

I am trying to style some nested unordered lists with CSS. When I use the IE7 standards or Quirks mode, the nested <li> elements get the background properties of their parents, the borders also don’t show correctly. I think that nesting the ul’s is causing the problem, and since I have a very good reason to do that, can anybody show me a CSS solution?

[code=html]<!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”>
<head>
<meta http-equiv=”Content-Type” content=”text/html; charset=utf-8″ />
<title>Nested ul’s</title>
<style type=”text/css”>
#div_menu {
margin: 0px;
padding: 0px;
width: 200px;
font-weight: normal;
position: absolute;
left: 10px;
top: 10px;
visibility: visible;
z-index: 10;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
border: 4px double #000;
}
#div_menu ul {
list-style: none;
padding: 0;
border: none;
margin: 0;
}
#div_menu li {
border-bottom: 1px solid #000;
margin: 0;
}
#div_menu li a {
display: block;
padding: 4px 5px 4px 5px;
color: #000;
text-decoration: none;
font-weight: bold;
background-color: #CCC;
}
#div_menu li a:hover {
background-color: #fff;
color: #017397;
}
#div_menu li.heading1 a {
display: block;
padding: 4px 5px 4px 5px;
color: #e5e5e5;
text-decoration: none;
font-weight: bold;
background-color: #000f19;
}
#div_menu li.heading1 a:hover {
background-color: #39769b;
color: #2f2401;
}
#div_menu li.heading2 a {
display: block;
padding: 4px 5px 4px 5px;
color: #e5e5e5;
text-decoration: none;
font-weight: bold;
background-color: #1186ac;
}
#div_menu li.heading2 a:hover {
background-color: #74ceeb;
color: #017397;
}
#div_menu li.heading3 a {
display: block;
padding: 4px 5px 4px 5px;
color: #e5e5e5;
text-decoration: none;
font-weight: bold;
background-color: #1d9ea0;
}
#div_menu li.heading3 a:hover {
background-color: #10dbdd;
color: #017397;
}
</style>
</head>

<body>
<div id=”div_menu”>
<ul>
<li class=”heading1″><a href=”#”>Heading 1</a></li>
<ul>
<li><a href=”#”>item 1.1</a></li>
<li><a href=”#”>item 1.2</a></li>
<li><a href=”#”>item 1.3</a></li>
<li><a href=”#”>item 1.4</a></li>
<li><a href=”#”>item 1.5</a></li>
<li><a href=”#”>item 1.6</a></li>
<li><a href=”#”>item 1.7</a></li>
<li><a href=”#”>item 1.8</a></li>
<li class=”heading2″><a href=”#”>Heading 2</a></li>
<ul>
<li><a href=”#”>item 2.1</a></li>
</ul>
<li class=”heading2″><a href=”#”>Heading 2</a></li>
<ul>
<li><a href=”#”>item 2.1</a></li>
<li><a href=”#”>item 2.2</a></li>
<li class=”heading3″><a href=”#”>Heading 3</a></li>
<ul>
<li><a href=”#”>item 3.1</a></li>
</ul>
</ul>
</ul>
<li class=”heading1″><a href=”#”>Heading 1</a></li>
<ul>
<li class=”heading2″><a href=”#”>Heading 2</a></li>
<ul>
<li><a href=”#”>item 2.1</a></li>
<li><a href=”#”>item 2.2</a></li>
</ul>
<li class=”heading2″><a href=”#”>Heading 2</a></li>
<ul>
<li><a href=”#”>item 2.1</a></li>
<li><a href=”#”>item 2.2</a></li>
<li><a href=”#”>item 2.3</a></li>
</ul>
</ul>
</ul>
</div>
</body>
</html>[/code]

to post a comment
CSS

4 Comments(s)

Copy linkTweet thisAlerts:
@bionoidJan 21.2013 — Hi,

Your child <ul> tags seemed illegally nested without <li> wrappers, so your markup has been changed here.

Some redundant CSS rules were commented out as well as quirks mode being activated using zoom on the main <ul>.

[code=html]<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nested ul's</title>
<style type="text/css">
#div_menu {
margin: 0px;
padding: 0px;
width: 200px;
font-weight: normal;
position: absolute;
left: 10px;
top: 10px;
visibility: visible;
z-index: 10;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
border: 4px double #000;
}
#div_menu ul {
list-style: none;
padding: 0;
border: none;
margin: 0;
zoom: 1;
}
#div_menu li {
border-bottom: 1px solid #000;
margin: 0;
}
#div_menu li a {
display: block;
padding: 4px 5px 4px 5px;
color: #000;
text-decoration: none;
font-weight: bold;
background-color: #CCC;
}
#div_menu li a:hover {
background-color: #fff;
color: #017397;
}
#div_menu li.heading1 a {
/* display: block;*/
/* padding: 4px 5px 4px 5px;*/
color: #e5e5e5;
/* text-decoration: none;*/
/* font-weight: bold;*/
background-color: #000f19;
}
#div_menu li.heading1 a:hover {
background-color: #39769b;
color: #2f2401;
}
#div_menu li.heading2 a {
/* display: block;*/
/* padding: 4px 5px 4px 5px;*/
color: #e5e5e5;
/* text-decoration: none;*/
/* font-weight: bold;*/
background-color: #1186ac;
}
#div_menu li.heading2 a:hover {
background-color: #74ceeb;
color: #017397;
}
#div_menu li.heading3 a {
/* display: block;*/
/* padding: 4px 5px 4px 5px;*/
color: #e5e5e5;
/* text-decoration: none;*/
/* font-weight: bold;*/
background-color: #1d9ea0;
}
#div_menu li.heading3 a:hover {
background-color: #10dbdd;
color: #017397;
}
</style>
</head>

<body>
<div id="div_menu">
<ul>

<li class="heading1"><a href="#">Heading 1</a></li>

<li>
<ul>
<li><a href="#">item 1.1</a></li>
<li><a href="#">item 1.2</a></li>
<li><a href="#">item 1.3</a></li>
<li><a href="#">item 1.4</a></li>
<li><a href="#">item 1.5</a></li>
<li><a href="#">item 1.6</a></li>
<li><a href="#">item 1.7</a></li>
<li><a href="#">item 1.8</a></li>
<li class="heading2"><a href="#">Heading 2</a></li>
<li>
<ul>
<li><a href="#">item 2.1</a></li>
</ul>
</li>
<li class="heading2"><a href="#">Heading 2</a></li>
<li>
<ul>
<li><a href="#">item 2.1</a></li>
<li><a href="#">item 2.2</a></li>
<li class="heading3"><a href="#">Heading 3</a></li>
<li>
<ul>
<li><a href="#">item 3.1</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>

<li class="heading1"><a href="#">Heading 1</a></li>

<li>
<ul>
<li class="heading2"><a href="#">Heading 2</a></li>
</ul>
</li>

<li><a href="#">item 2.1</a></li>
<li><a href="#">item 2.2</a></li>

<li class="heading2"><a href="#">Heading 2</a></li>

<li>
<ul>
<li><a href="#">item 2.1</a></li>
<li><a href="#">item 2.2</a></li>
<li><a href="#">item 2.3</a></li>
</ul>
</li>
</ul>

</div>

</body>
</html>[/code]
Copy linkTweet thisAlerts:
@Vassil_CatsarovauthorJan 22.2013 — bionoid,

Thank you for pointing out the need for the <li> wrappers around my nested ul's. In your example the lower border of the newly added <li> tags sums up and becomes unequally thick - can be best seen on mouse hovering over Heading 1, immediately following item 3.1. Do you know how can I resolve that problem with css only? What I did was to apply a new class with border: none to the newly added <li> tags. And what do you mean by "quirks mode being activated using zoom on the main <ul>"?
Copy linkTweet thisAlerts:
@bionoidJan 22.2013 — Hi,

I moved your bordering away from the <li> tags and placed it on the <a> tags instead, that way you would only get a double line at the bottom the the list.

[code=html]<!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">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Nested ul's</title>
<style type="text/css">
#div_menu {
margin: 0px;
padding: 0px;
width: 200px;
font-weight: normal;
position: absolute;
left: 10px;
top: 10px;
visibility: visible;
z-index: 10;
font-family: Arial, Helvetica, sans-serif;
font-size: 14px;
border: 4px double #000;
}
#div_menu ul {
list-style: none;
padding: 0;
border: none;
margin: 0;
zoom: 1;
}
#div_menu li {
margin: 0;
}
#div_menu li a {
display: block;
padding: 4px 5px 4px 5px;
color: #000;
text-decoration: none;
font-weight: bold;
background-color: #CCC;
border-bottom: 1px solid #000;
}
#div_menu li a:hover {
background-color: #fff;
color: #017397;
}
#div_menu li.heading1 a {
/* display: block;*/
/* padding: 4px 5px 4px 5px;*/
color: #e5e5e5;
/* text-decoration: none;*/
/* font-weight: bold;*/
background-color: #000f19;
}
#div_menu li.heading1 a:hover {
background-color: #39769b;
color: #2f2401;
}
#div_menu li.heading2 a {
/* display: block;*/
/* padding: 4px 5px 4px 5px;*/
color: #e5e5e5;
/* text-decoration: none;*/
/* font-weight: bold;*/
background-color: #1186ac;
}
#div_menu li.heading2 a:hover {
background-color: #74ceeb;
color: #017397;
}
#div_menu li.heading3 a {
/* display: block;*/
/* padding: 4px 5px 4px 5px;*/
color: #e5e5e5;
/* text-decoration: none;*/
/* font-weight: bold;*/
background-color: #1d9ea0;
}
#div_menu li.heading3 a:hover {
background-color: #10dbdd;
color: #017397;
}
</style>
</head>

<body>
<div id="div_menu">
<ul>

<li class="heading1"><a href="#">Heading 1</a></li>

<li>
<ul>
<li><a href="#">item 1.1</a></li>
<li><a href="#">item 1.2</a></li>
<li><a href="#">item 1.3</a></li>
<li><a href="#">item 1.4</a></li>
<li><a href="#">item 1.5</a></li>
<li><a href="#">item 1.6</a></li>
<li><a href="#">item 1.7</a></li>
<li><a href="#">item 1.8</a></li>
<li class="heading2"><a href="#">Heading 2</a></li>
<li>
<ul>
<li><a href="#">item 2.1</a></li>
</ul>
</li>
<li class="heading2"><a href="#">Heading 2</a></li>
<li>
<ul>
<li><a href="#">item 2.1</a></li>
<li><a href="#">item 2.2</a></li>
<li class="heading3"><a href="#">Heading 3</a></li>
<li>
<ul>
<li><a href="#">item 3.1</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>

<li class="heading1"><a href="#">Heading 1</a></li>

<li>
<ul>
<li class="heading2"><a href="#">Heading 2</a></li>
</ul>
</li>

<li><a href="#">item 2.1</a></li>
<li><a href="#">item 2.2</a></li>

<li class="heading2"><a href="#">Heading 2</a></li>

<li>
<ul>
<li><a href="#">item 2.1</a></li>
<li><a href="#">item 2.2</a></li>
<li><a href="#">item 2.3</a></li>
</ul>
</li>
</ul>

</div>

</body>
</html>[/code]


You will see I used a zoom css rule on the "#div_menu ul" selector. I might have termed it wrong, could also be called hasLayout. If you remove that rule you will understand why I placed it there. Was only to keep IE7 happy, the more modern browsers don't require it.

http://www.bennadel.com/blog/1354-The-Power-Of-ZOOM-Fixing-CSS-Issues-In-Internet-Explorer.htm
Copy linkTweet thisAlerts:
@Vassil_CatsarovauthorJan 22.2013 — Yes, I was going to inspect the css because your example was doing the job while mine actual project was expanding the empty <li> tags containing the nested <ul>'s.

I have never heard of the zoom css property, so without your help I could have never have made it. So thanks a lot, bionoid. As a conclusion, I don't think anymore that using a styled unordered list is a great idea to create a menu.
×

Success!

Help @Vassil_Catsarov 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.18,
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,
)...