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.

[HELP] CSS DropDown

Featured Replies

Hey!

 

I ran into a little problem with my design, I am constructing a website, and needed a drop-down menu, so obviously, I coded one. However, the drop-down menu decided not to work in IE.

 

Would anyone be kind to share ideas on how I could get it to work?

 

CSS

nav { float: right; }
nav ul { list-style-type: none; }
nav ul li { float: left; padding: 6px; display: block; margin-right: 20px; }
nav ul li a { color: #fff; text-decoration: none; font-weight: bold; }
nav ul li a:hover { color: #ccc; }
nav li ul { display: none; margin-top: 8px; position: absolute; margin-left: -40px; z-index: 1;  }
li:hover > ul { display: block; }
nav li:hover li { float: none; font-size: 11px; background: #1f3b08; border: 1px solid #527c13; border-top: 0; }
.hp { height: 20px; }

 

 

HTML


 

Yes, I am using HTML5, and the trunk is loaded ;) - I did have it working at one point, but for some reason it just broke.

please do with this code

 

 

css code

 

#menu

{

margin: 0px;

padding: 0px;

list-style: none;

color: #a9a9a9;

text-decoration: none;

line-height: 45px;

display: inline-block;

float: left;

z-index: 2;

}

#menu a

{

color: #a9a9a9;

text-decoration: none;

}

#menu > li

{

cursor: pointer;

float: left;

position: relative;

padding: 0px 10px;z-index: 2;

}

#menu > li a:hover

{

color: #c9a628;

}

#menu ul

{

padding: 0px;

margin: 0px;

display: block;

display: inline;z-index: 2;

}

#menu li ul

{

position: absolute;

left: -10px;

top: 0px;

margin-top: 45px;

width: 150px;

line-height: 12px;

background-color: #18181a;

color: #0395CC; /* for IE */

display: none;

}

#menu li:hover ul

{

display: block;z-index: 2;

 

}

#menu li ul li

{

display: block;

margin: 2px 20px;

padding: 5px 0px;

border-top: dotted 1px #ffffff;

list-style-type: none;

}

#menu li ul li:first-child

{

border-top: none;

}

#menu li ul li a

{

display: block;

color: #a9a9a9;

}

#menu li ul li a:hover

{

color: #c9a628;

}

 

html code

<ul id="menu">

 

<li><a href="services.html">Services</a></li>

<li><a href="portfolio.html">Portfolio</a>

<ul id="help">

<li><a href="#">link1</a></li>

<li><a href="#">link2</a></li>

<li><a href="#">link3</a></li>

<li><a href="#">link4</a></li>

</ul>

</li>

</ul>

  • Author

there's no HTML code?

 

There was :s

Here it is:

<!-- Navigation -->
<nav>
<ul>
	<li><a href="index.php">Home</a></li>
	<li><a href="forums/index.php">Forums</a></li>
	<li class="hp"><a href="diyprojects.php">DIY Projects ▾</a><ul>
		<li><a href="milestag.php">MilesTag</a></li>
		<li><a href="q-tag.php">Q-Tag</a></li>
	</ul>
	</li>
	<li class="hp"><a href="GunC.php" >Gun Construction ▾</a>
	<ul>
		<li><a href="lens-calc.php">Lens Calculator</a></li>
	</ul>
	</li>
	<li><a href="commercial.php">Commercial</a></li>
	<li><a href="contact.php">Contact Us</a></li>
	<li><a href="chat.php">Chat</a></li>
</ul>
</nav>      
<!-- End Nav -->

 

Pure CSS drop down menus can be tricky to code, especially for IE6.

 

Have you seen cssplay? http://www.cssplay.co.uk/menus/

 

It's often better to start with one of those that is nearly what you want and edit it.

 

I have had a look there, but, ill have another look!

 

 

please do with this code

 

 

css code

 

#menu

{

margin: 0px;

padding: 0px;

list-style: none;

color: #a9a9a9;

text-decoration: none;

line-height: 45px;

display: inline-block;

float: left;

z-index: 2;

}

#menu a

{

color: #a9a9a9;

text-decoration: none;

}

#menu > li

{

cursor: pointer;

float: left;

position: relative;

padding: 0px 10px;z-index: 2;

}

#menu > li a:hover

{

color: #c9a628;

}

#menu ul

{

padding: 0px;

margin: 0px;

display: block;

display: inline;z-index: 2;

}

#menu li ul

{

position: absolute;

left: -10px;

top: 0px;

margin-top: 45px;

width: 150px;

line-height: 12px;

background-color: #18181a;

color: #0395CC; /* for IE */

display: none;

}

#menu li:hover ul

{

display: block;z-index: 2;

 

}

#menu li ul li

{

display: block;

margin: 2px 20px;

padding: 5px 0px;

border-top: dotted 1px #ffffff;

list-style-type: none;

}

#menu li ul li:first-child

{

border-top: none;

}

#menu li ul li a

{

display: block;

color: #a9a9a9;

}

#menu li ul li a:hover

{

color: #c9a628;

}

 

html code

<ul id="menu">

 

<li><a href="services.html">Services</a></li>

<li><a href="portfolio.html">Portfolio</a>

<ul id="help">

<li><a href="#">link1</a></li>

<li><a href="#">link2</a></li>

<li><a href="#">link3</a></li>

<li><a href="#">link4</a></li>

</ul>

</li>

</ul>

 

I'll give that a try! :)

Edited by Blake

  • Author

@a1visions

 

Your code is nice, works in Chrome, Firefox, Safari and Opera, but doesn't work in IE8/7/6 still..

 

Thanks for your efforts though!

The issue with IE6 is it dosent support :hover on anything other than anchor tags.

 

you could try changing the css to #ul li a:hover ul rather than #ul li:hover ul

 

although pure CSS dropdowns are prefferable the only way I have found to solve the issues accross the board is using javascript (ideally jQuery) to add/remove a class which changes the display of the element.

 

try the :hover on the anchor first if you have no luck I will give you some jQuery to solve the issue.

  • Author

The issue with IE6 is it dosent support :hover on anything other than anchor tags.

 

you could try changing the css to #ul li a:hover ul rather than #ul li:hover ul

 

although pure CSS dropdowns are prefferable the only way I have found to solve the issues accross the board is using javascript (ideally jQuery) to add/remove a class which changes the display of the element.

 

try the :hover on the anchor first if you have no luck I will give you some jQuery to solve the issue.

 

I'll give that a try, thanks.

 

 

If IE6 support matters to you, ditch the HTML5. IE6 isn't all that great at rendering elements it DOES recognise.

 

IE6 can go screw itself, haha. I hate IE6, it doesn't really matter if it doesn't work in IE6, but would be better if it did. :)

  • Author

For some reason, one of my clients websites I designed: http://www.hosting-security-specialists.com/ (hover over hosting) the HTML5 Nav I coded for him works in IE7/8, I copied the code rather than re-writing it and it still doesn't work :S

Edited by Blake

have you a link to the site you are working on?

  • Author

have you a link to the site you are working on?

 

Im working on it locally, if you (theres a version on here: http://www.lazercrew.co.uk/newsite

 

However, it doesn't matter now, Im using a menu from http://www.noupe.com/tutorial/drop-down-menu-jquery-css.html

 

:D

 

Thanks for all your help guys, much appreciated!

just tried it quickly and IE8 doesn't like your HTML5 doctyp. Changed it to a transitional affair and the dropdowns work (ish)

  • Author

actually you can change your doctyp to just <!DOCTYPE html>

 

which is as it should be? http://www.w3schools.com/html5/tag_doctype.asp

and not just <html>

 

If that's the case then which browsers are adhering to standards and which aren't?

 

Ahh! No wonder! It must of disappeared! Didn't even check that! (DOH!) - Thanks guys!

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.