Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

IE/Firefox and CSS nested lists

Featured Replies

Hi,

 

I wanted to have a nested CSS-styled list where the subelements would show horizontal (on the same level) as parents.

While FF does it as it should, the IE...figures...does not.

 

As snippets:

HTML LIST:

<div class="projects">
<div class="headings">First heading</div>
<ul>
<li>List item 1</li>
<li class="projectthumbs">
  <ul>
     <li><a href='' imgsrc='/images/projects/pic_1a.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1b.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1c.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1d.jpg'></a></li>
  </ul>
 </li>
</ul>
(...)
</div>

CSS STYLING:

.headings {
   font-size: 12px;
   font-family: Verdana, Geneva, sans-serif;
   font-weight: normal;
   text-transform: uppercase;
   text-align: left;
   font-weight:bold;
   color: #B82129;
   padding-bottom: 5px;
   padding-top: 5px;
}

.projects {
   font-size: 11px;
   font-family: Verdana, Geneva, sans-serif;
   list-style-type: none;
}

.projects ul {
   margin: 0;
   list-style-type: none;
}

.projects li {
   margin: 0;
   padding-top: 1px;
   padding-bottom: 1px;
   display: inline-table;
}


.projectthumbs {
   font-size: 14px;
}

.projectthumbs ul {
   height: 10px;
   padding: 0 0 1px 15px
}

.projectthumbs li {
   float: left;
   list-style-type: none;
   height: 12px;
   width: 12px;
   margin: 0 3px 0 0;
   display: inline-table;
}

.projectthumbs li a{
   padding: 0;
   color: #FFFFFF;
   background-color: #999999;
   width: 8px;
   height: 12px;
   padding: 0 2px;
   display: block;
}

.projectthumbs li a:active {
   background-color: #B82129;
}
.projectthumbs li a:hover {
   background-color: #B82129;
}

/*.projectthumbs li a:visited {*/
/*    background-color: #433e39;*/
/*}*/

 

Sorry for messy CSS, I have some redunancies which I have to still work on...

 

Here is the FF and IE7 rendering:

FF: list_FF.JPG

IE7: list_IE7.JPG

 

The code could be found at: http://www.shepdev.pcriot.com/list.html.

This works in IE7 and Firefox:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"     
"http://www.w3.org/TR/html4/strict.dtd"> 
<html>
<head>
<meta name="keywords" content="Wickham">                
<meta name="description" content="Test items">            
<meta http-equiv="content-type" content="text/html; 
charset=iso-8859-1">

<title>Test</title>                  

<style type="text/css">

.headings {
   font-size: 12px;
   font-family: Verdana, Geneva, sans-serif;
   font-weight: normal;
   text-transform: uppercase;
   text-align: left;
   font-weight:bold;
   color: #B82129;
   padding-bottom: 5px;
   padding-top: 5px;
}

.projects {                   
   font-size: 11px;
   font-family: Verdana, Geneva, sans-serif;
   list-style-type: none;
}

.projects ul {                
   margin: 0;
   list-style-type: none;
}

.projects li { 
   margin: 0;
   padding-top: 1px;
   padding-bottom: 1px;
   display: inline-table;         float: left;
}

.projectthumbs {         
   font-size: 14px;
}

.projectthumbs ul {                 margin: 0; 
   height: 10px;
   padding: 0 0 1px 15px
}

.projectthumbs li {
   float: left;
   list-style-type: none;
   height: 12px;
   width: 12px;
   margin: 0 3px 0 0;
   display: inline-table;
}

.projectthumbs li a{              
   padding: 0;
   color: #FFFFFF;
   background-color: #999999;
   width: 8px;
   height: 12px;
   padding: 0 2px;
   display: block;
}

.projectthumbs li a:active {
   background-color: #B82129;
}
.projectthumbs li a:hover {
   background-color: #B82129;
}

.clear { float: none; width: 100%; height: 0; line-height: 0; font-size: 0; }


/*.projectthumbs li a:visited {*/
/*    background-color: #433e39;*/
/*}*/

</style>

</head>

<body> 

<div class="projects">
<div class="headings">First heading</div>
<ul>
<li>List item 1</li>
<li class="projectthumbs">
  <ul>
     <li><a href='' imgsrc='/images/projects/pic_1a.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1b.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1c.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1d.jpg'></a></li>
  </ul>
 </li>
<li class="clear"> </li>
<li>List item 2</li>
<li class="projectthumbs">
  <ul>
     <li><a href='' imgsrc='/images/projects/pic_1a.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1b.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1c.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1d.jpg'></a></li>
  </ul>
 </li>

</ul>

</div>

</body>
</html>

 

I needed to add float: left; to .projects li and also a full-width nil-height li tag to form a full-width barrier between the floated items. If you add clear: both to the li tag that has List 2 that will form a new line but the following li tag class="projectthumbs" would jump up over it alongside the first one, so a full-width barrier is necessary between the sections.

 

My code is a bit clumsy and possibly could be simplified.

I didn't code as far as the Second Heading so I agree with the other answer that .headings needs clear: left;

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"        
"http://www.w3.org/TR/html4/strict.dtd"> 
<html>
<head>
<meta name="keywords" content="Wickham">                
<meta name="description" content="Test items">            
<meta http-equiv="content-type" content="text/html; 
charset=iso-8859-1">

<title>Test</title>                  

<style type="text/css">

.headings { clear: left;
   font-size: 12px;
   font-family: Verdana, Geneva, sans-serif;
   font-weight: normal;
   text-transform: uppercase;
   text-align: left;
   font-weight:bold;
   color: #B82129;
   padding-bottom: 5px;
   padding-top: 5px;
}

.projects {                   
   font-size: 11px;
   font-family: Verdana, Geneva, sans-serif;
   list-style-type: none;
}

.projects ul {               
   margin: 0;
   list-style-type: none;
}

.projects li { 
   margin: 0;
   padding-top: 1px;
   padding-bottom: 1px;
   display: inline-table;         float: left;
}

.projectthumbs {         
   font-size: 14px;
}

.projectthumbs ul {                 margin: 0; 
   height: 10px;
   padding: 0 0 1px 15px
}

.projectthumbs li {
   float: left;
   list-style-type: none;
   height: 12px;
   width: 12px;
   margin: 0 3px 0 0;
   display: inline-table;
}

.projectthumbs li a{              
   padding: 0;
   color: #FFFFFF;
   background-color: #999999;
   width: 8px;
   height: 12px;
   padding: 0 2px;
   display: block;
}

.projectthumbs li a:active {
   background-color: #B82129;
}
.projectthumbs li a:hover {
   background-color: #B82129;
}

.clear { float: none; width: 100%; height: 0; line-height: 0; font-size: 0; }


/*.projectthumbs li a:visited {*/
/*    background-color: #433e39;*/
/*}*/

</style>

</head>

<body> 

<div class="projects">

<div class="headings">First heading</div>
<ul>
<li>List item 1</li>
<li class="projectthumbs">
  <ul>
     <li><a href='' imgsrc='/images/projects/pic_1a.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1b.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1c.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1d.jpg'></a></li>
  </ul>
 </li>
<li class="clear"> </li>
<li>List item 2</li>
<li class="projectthumbs">
  <ul>
     <li><a href='' imgsrc='/images/projects/pic_1a.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1b.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1c.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1d.jpg'></a></li>
  </ul>
 </li>

</ul>

<div class="headings">Second heading</div>
<ul>
<li>List item 1</li>
<li class="projectthumbs">
  <ul>
     <li><a href='' imgsrc='/images/projects/pic_1a.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1b.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1c.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1d.jpg'></a></li>
  </ul>
 </li>
<li class="clear"> </li>
<li>List item 2</li>
<li class="projectthumbs">
  <ul>
     <li><a href='' imgsrc='/images/projects/pic_1a.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1b.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1c.jpg'></a></li>
     <li><a href='' imgsrc='/images/projects/pic_1d.jpg'></a></li>
  </ul>
 </li>

</ul>

</div>

</body>
</html>

 

There always seem to be several ways to cure a problem. You (or the other answer) have started a new ul tag for List 2 in each section whereas I continued with li tags inside the same ul tag, separating the sections with a full-width nil-height li tag to clear the floats.

  • Author

Ah! Thanks for pointing it out, now (after playing with it) I see what you did, very clever with continuing the LI but clearing all the floats!

Thanks :)

  • Author

hmmm...actually maybe you can help me with another problem...

 

I have currently commented out this section:

 

/*.projectthumbs li a:visited {*/

/* background-color: #433e39;*/

/*}*/

 

...because it would change all of the backgrounds (even not visited to the above color).

This should be very trivial but it is not working for me...

 

I wanted to have the squares/background color od the projectthumbs list as follows:

link: #999999;

hover/active: #B82129;

visited: #433e39;

 

 

Any idea what could be wrong?

 

Thanks again!

This works in IE7 and Firefox:-

.projectthumbs li a:link {
   background-color: #999999;
}
.projectthumbs li a:visited {
   background-color: #433e39;
}

.projectthumbs li a:hover, .projectthumbs li a:active {
   background-color: #b82129;
}

 

Hover works but I can't test visited without working links, but that should work too. Remember to keep the order link, visited, hover, active. The link state is dark like the visited state until you add a working link to an image.

 

Instead of this

<li><a href='' img src='/images/projects/pic_1a.jpg'></a></li>

 

I would expect this

<li><a href='/images/projects/pic_1a.jpg'></a></li>

  • Author

Thanks Wickham!

 

I had the blank href temporarily and didn't realize it would affect the test, but you are right.

 

I added some test images and modified the style sheet: http://www.shepdev.pcriot.com/list2.html

 

.projectthumbs li a:link {
   background-color: #999999;
}
.projectthumbs li a:visited {
   background-color: #b82129;
}

.projectthumbs li a:hover, .projectthumbs li a:active {
   background-color: #b82129;
}

 

 

 

For whatever reason though, the visited background becomes the same as the page background, even though for the sake of test I set it to a very visible color (same as the hover/active). So that after you click and visit images, eventually your gray squares disappear :(

Be very careful with the ' or " around image urls. You left out one at the end here

<li><a href='images/Bricks.bmp></a></li>

and it affected the whole layout of the List 2 First Heading.

 

The different colors worked in my test and I see that you've got different styles. Add in .projectthumbs li a , delete the first one for .projectthumbs li a:link and edit the visited color:-

.projectthumbs li a{              
   padding: 0;
   color: #FFFFFF;
   background-color: #999999;
   width: 8px;
   height: 12px;
   padding: 0 2px;
   display: block;
}

/*.projectthumbs li a:link{              
   padding: 0;
   color: #FFFFFF;
   background-color: #999999;
   width: 8px;
   height: 12px;
   padding: 0 2px;
   display: block;
}*/

.projectthumbs li a:link {
   background-color: #999999;
}
.projectthumbs li a:visited {
   background-color: #433e39; /*was #b82129;*/
}

.projectthumbs li a:hover, .projectthumbs li a:active {
   background-color: #b82129;
}

 

I substituted my own images and they all worked in Firefox but in IE7 bmp and png images loaded in a new window but jpg images didn't load. I'm not sure why that is.

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.