Solved

CSS horizontal drop down menu not showing correctly in IE

Posted on 2008-09-29
12
907 Views
Last Modified: 2012-05-05
Hello,

I am trying to do a pure CSS menu and am having issues - especially with IE. The code I borrowed from displays correctly in IE but mine doesn't. I did add some CSS for the sub-level menus but I can't figure out what is causing the issue.

Here is the site that I used as an example which displays correctly in IE7:
http://www.cssplay.co.uk/menus/centered.html

Here is the html I am using:
<div id="menu_cont">
  <div id="menu">

    <ul id="nav">
      <li><a href="index.htm" class="top_parent">HOME</a></li>
      <li><a href="opportunities.htm" class="top_parent">OPPORTUNITIES</a>
          <ul>
            <li><a href="opportunities/current_promotions.htm">Current Promotions</a></li>
            <li><a href="opportunities/go_green.htm">Go Green With CPS</a></li>
            <li><a href="opportunities/news_events.htm">News/Events</a></li>

            <li><a href="opportunities/partner_rewards.htm">Partner and Rewards Programs</a></li>
            <li><a href="opportunities/training.htm">Training</a></li>
          </ul>
      </li>
      <li><a href="opportunities/credit.htm" class="top_parent">CREDIT</a></li>
      <li><a href="products/product_lines.htm" class="top_parent">PRODUCTS</a>
          <ul>

            <li><a href="products/cut_sheets.htm">Cut Sheets</a></li>
            <li><a href="products/product_lines.htm">Product Lines</a>
                <ul>
                  <li><a href="products/irrigation.htm">Irrigation</a></li>
                  <li><a href="products/landscape.htm">Landscape</a></li>
                  <li><a href="products/lighting.htm">Lighting</a></li>

                  <li><a href="products/pump.htm">Pump</a></li>
                  <li><a href="products/ponds_water_features.htm">Ponds and Water Features</a></li>
                </ul>
            </li>
            <li><a href="products/request_catalog.htm">Request a Catalog</a></li>
          </ul>
      </li>

      <li><a href="locations/branch_offices.htm" class="top_parent">LOCATIONS</a>
          <ul>
            <li><a href="locations/branch_offices.htm">Branch Offices</a></li>
            <li><a href="locations/territory_sales.htm">Territory Salespeople</a></li>
          </ul>
      </li>
      <li><a href="why_cps/inside_cps.htm" class="top_parent">WHY CPS</a>

          <ul>
            <li><a href="why_cps/cps_showcase.htm">CPS Showcase</a></li>
            <li><a href="why_cps/inside_cps.htm">Inside CPS</a></li>
            <li><a href="why_cps/employee_corner.htm">Employee Corner</a></li>
          </ul>
      </li>
      <li><a href="links.htm" class="top_parent">LINKS</a></li>

      <li><a href="employment/current_openings.htm" class="top_parent">EMPLOYMENT</a>
          <ul>
            <li><a href="employment/benefits.htm">Benefits</a></li>
            <li><a href="employment/current_openings.htm">Current Openings</a></li>
          </ul>
      </li>
      <li><a href="locations/policies.htm" class="top_parent">POLICIES</a></li>

    </ul>
  </div>
</div>

I've attached the css for the menu as a snippet. Also, here is the link to the full css:
http://cpsdistributors.com/test/cps_styles.css

Here is the ie only style sheet:
#menu {
  float:left;
  }
#menu a {
  float:left;
  display: inline;
  }
#menu li {
  float:left;
  }
.container {display:inline-block;}

Thank you!
#menu_cont {

	width:900px;

	height: 20px;

	padding-top:9px;

	margin:0 auto;

	background: url(images/menu_bkgnd.jpg) no-repeat center top;

}

/*begin menu*/

#menu{

	font: bold 11pt "Trebuchet MS", Tahoma, Arial, sans-serif;

	margin:0 auto;

	padding:0;

	list-style-type:none;

    white-space:nowrap;

	display:table;

}

#menu a{

	width:auto;

	color: #fff;

    display:block;

	text-decoration: none;

    white-space:nowrap;

	padding:0px 16px;

}

#menu li { /* all list items */

	display:table-cell;

	background: none;

    white-space:nowrap;

  }

.container {clear:both; text-decoration:none;}

#menu li li {

	width: 100%;

	display: block;

	}

#menu li li li{

	width: 100%;

	display: block;

	}

#menu li ul{

/*Make the sub list items invisible*/

	display: none;	

	left: -999em;

	position: absolute;

	}

#menu li:hover ul ul, #menu li.over ul ul{

/*Make the second-level list items invisible*/

	display: none;

	position: absolute;

	left: -999em;

}

#menu li:hover ul, #menu li.over ul{ 

/* lists nested under hovered list items */

	display: block;

	left: auto;

	font: bold 10pt "Trebuchet MS", Verdana, Arial, sans-serif;

	white-space: nowrap;

	background-color: #7FA97F;

	padding: 6px 0px;

	filter:alpha(opacity=90);

	-moz-opacity:.90;

	opacity:.90;

	text-align: left;

}

#menu li li:hover ul, #menu li li.over ul { 

/* second-level lists nested under hovered list items */

	display: block;

	left: 90%;

	width: auto;

	top: 16px;

	font: bold 10pt "Trebuchet MS", Verdana, Arial, sans-serif;

	white-space: nowrap;

	background-color: #7FA97F;

	padding: 6px 0px;

	filter:alpha(opacity=100);

	-moz-opacity:1.0;

	opacity:1.0;

	text-align: left;

}

#menu a, #menu a:visited {color:#fff; text-decoration:none; }

#menu a:hover, #menu a:active {color:#000; text-decoration:none; 

	background-color: #96BB96;}

/*end menu*/

Open in new window

0
Comment
Question by:maxms
  • 5
  • 4
  • 3
12 Comments
 
LVL 14

Expert Comment

by:EMB01
ID: 22599502
What about it doesn't display properly in IE?
0
 

Author Comment

by:maxms
ID: 22599649
It stacks vertically in IE7:
http://www.cpsdistributors.com/test
0
 
LVL 14

Expert Comment

by:EMB01
ID: 22600029
Have you tried adding clear: left; to your CSS like this...
#menu li { /* all list items */
      display:table-cell;
      background: none;
                     white-space:nowrap;
                     clear: left;
}

Or, you could try adding display: inline; to the primary li node so that it stacks left to right...
#menu li { /* all list items */
      display:table-cell;
      background: none;
                     white-space:nowrap;
                     display: inline;
}

Let me know if these don't work for you, then we can take a closer look and try to work somehting else out.
0
 
LVL 42

Expert Comment

by:David S.
ID: 22600891
IE7 doesn't support display:table-cell

Try adding these rules:

*:first-child+html #menu li { /* for IE7 */
  display: inline-block;  
}
* html #menu li { /* for IE5-6 */
   display: inline;
  display: inline-block;  
}

Here's another article on this: http://www.tyssendesign.com.au/articles/css/centering-a-dropdown-menu/
0
 
LVL 42

Expert Comment

by:David S.
ID: 22600948
On second thought, this might work better:

#menu li { /* all list items */
  display: inline-block;
  display: table-cell;
  background: none;
  white-space: nowrap;
}
*:first-child+html #menu li { /* for IE7 */
  display: inline;
}
* html #menu li { /* for IE5-6 */
  display: inline;
}

0
 

Author Comment

by:maxms
ID: 22601435
Thank you both for your comments but none of these options worked. So, I went back to my original CSS, which didn't use table display and added a few things from the article that Kravimir posted and it now displays horizontally centered in IE7 (woo-hoo!) except that these problems also show in IE7:

1. It is wrapping to the next line. I put the following into an IE7-only css doc but it doesn't appear to be picking it up:
*html #menu a{
      padding:0px 14px;
}

2. The second-level child menu (on the 'Products' drop-down off of the 'Product Lines' child) Isn't displaying correctly. You can see the beginning of it, but it cuts off at the end of the first child menu.

The original CSS is below.
#menu_cont {

	width:900px;

	height: 20px;

	padding-top:9px;

	margin:0 auto;

	background: url(images/menu_bkgnd.jpg) no-repeat center top;

	text-align: center;

}

/*begin menu*/

#menu, #menu ul{

	font: bold 11pt "Trebuchet MS", Tahoma, Arial, sans-serif;

	margin:0 auto;

	padding:0;

	list-style-type:none;

    white-space:nowrap;

	text-align: center;

}

#menu a{

	width:auto;

	color: #fff;

    display:block;

	text-decoration: none;

    white-space:nowrap;

	padding:0px 16px;

}

#menu li { /* all list items */

	float: left;

	position: relative;

	width: auto;

	background: none;

}

#menu li li {

	width: 100%;

	}

#menu li li li{

	width: 100%;

	}

#menu li ul{

/*Make the sub list items invisible*/

	display: none;	

	left: -999em;

	position: absolute;

	}

#menu li>ul{

	top: auto;

	left: auto;

}

#menu li:hover ul ul, #menu li.over ul ul{

/*Make the second-level list items invisible*/

	display: none;

	position: absolute;

	left: -999em;

}

#menu li:hover ul, #menu li.over ul{ 

/* lists nested under hovered list items */

	display: block;

	left: auto;

	font: bold 10pt "Trebuchet MS", Verdana, Arial, sans-serif;

	white-space: nowrap;

	background-color: #7FA97F;

	padding: 6px;

	filter:alpha(opacity=90);

	-moz-opacity:.90;

	opacity:.90;

	text-align: left;

}

#menu li li:hover ul, #menu li li.over ul { 

/* second-level lists nested under hovered list items */

	display: block;

	left: 100%;

	width: auto;

	top: -6px;

	font: bold 10pt "Trebuchet MS", Verdana, Arial, sans-serif;

	white-space: nowrap;

	background-color: #7FA97F;

	padding: 6px;

	filter:alpha(opacity=100);

	-moz-opacity:1.0;

	opacity:1.0;

	text-align: left;

}

#menu a, #menu a:visited {color:#fff; text-decoration:none; }

#menu a:hover, #menu a:active {color:#000; text-decoration:none; 

	background-color: #96BB96;}

/*end menu*/

Open in new window

0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:maxms
ID: 22601503
Ok - fixed the wrapping by just lowering the padding to 15px. Now I just need to figure out why the second-level child is displaying so oddly... any help would be greatly appreciated!!!

Thank you!
0
 
LVL 42

Expert Comment

by:David S.
ID: 22601516
In Standards mode, IE7 ignores the "* html" filter. Use the "*:first-child+html" filter instead.

More information:
http://www.dynamicsitesolutions.com/css/filters/star-html/
http://www.dynamicsitesolutions.com/css/filters/first-child-plus-html/
0
 
LVL 42

Expert Comment

by:David S.
ID: 22601566
<!--[if IE7]>

needs to be

<!--[if IE 7]>

A space is required before the number.

I don't see what's causing the current IE7 issue. I think we've reached the point where you're going to have to comment out each declaration (property/value pair) and test to see if it makes a difference one at a time to find the problem.
0
 
LVL 14

Expert Comment

by:EMB01
ID: 22601601
Maybe change this:
#menu li li:hover ul, #menu li li.over ul {
/* second-level lists nested under hovered list items */
      display: block;
      left: 100%;
      width: auto;
      top: -6px;
      font: bold 10pt "Trebuchet MS", Verdana, Arial, sans-serif;
      white-space: nowrap;
      background-color: #7FA97F;
      padding: 6px;
      filter:alpha(opacity=100);
      -moz-opacity:1.0;
      opacity:1.0;
      text-align: left;
}

To this:
#menu li li:hover ul, #menu li li.over ul {
/* second-level lists nested under hovered list items */
      display: block;
      left: auto;
      top: -6px;
      font: bold 10pt "Trebuchet MS", Verdana, Arial, sans-serif;
      white-space: nowrap;
      background-color: #7FA97F;
      padding: 6px;
      filter:alpha(opacity=100);
      -moz-opacity:1.0;
      opacity:1.0;
      text-align: left;
}
0
 

Author Comment

by:maxms
ID: 22625980
None of this is working, so I will do some intense testing today and let you know how it goes. Otherwise I may have to create the menu using JavaScript...
0
 

Accepted Solution

by:
maxms earned 0 total points
ID: 22708096
I figured it out - I just had to remove this from the third level list style:

"filter:alpha(opacity=100);"

Thanks for trying!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction A frequently asked question goes something like this:  "I am running a long process in the background and I want to alert my client when the process finishes.  How can I send a message to the browser?"  Unfortunately, the short answer …
This is a how to build your own CSS3 slideshow and when I say CSS3 I mean just CSS with no javascript in sight! There a few examples online of how to do this but most just show you an example without any explanation, others make it more complicat…
In this tutorial viewers will learn how add a scalable full-width header using CSS3. Create a new HTML document with an internal stylesheet. Set a tiled background.:  Create a new div and name it Header. Position it with position:absolute at the top…
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…

863 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now