www.webdeveloper.com
Results 1 to 5 of 5

Thread: Nested unordered lists compatibility issues in IE

Hybrid View

  1. #1
    Join Date
    May 2003
    Location
    Bulgaria
    Posts
    149

    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?

    HTML Code:
    <!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>

  2. #2
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    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>.

    HTML Code:
    <!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>
    JavaScript: Learn | Validate | Compact | bionoid

  3. #3
    Join Date
    May 2003
    Location
    Bulgaria
    Posts
    149
    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>"?
    Last edited by Vassil Catsarov; 01-22-2013 at 06:39 AM.

  4. #4
    Join Date
    Dec 2011
    Location
    Centurion, South Africa
    Posts
    792
    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.

    HTML Code:
    <!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>
    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-Th...t-Explorer.htm
    JavaScript: Learn | Validate | Compact | bionoid

  5. #5
    Join Date
    May 2003
    Location
    Bulgaria
    Posts
    149
    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.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles