Web Design Forum  
 
Go Back   Web Design Forum > Web and Graphic Design > Web Design

Reply
 
LinkBack Thread Tools Display Modes
Old 04-11-2011, 03:28 AM   #1
Platinum Member
 
ronaldroe's Avatar
 
Join Date: Jan 2011
Location: Oklahoma City, OK
Posts: 676
Send a message via Skype™ to ronaldroe
Default CSS-Only Dropdown Menu

I wanted a quick dropdown for my website navigation that wasn't scripted, and zero flash. After reading about it, I drilled the code down to only the basics so I could build from that.

So, without further ado, the code below is the CSS-only dropdown menu styled just enough to make the concept look like something you'd expect to use:

HTML
Quote:
<ul id="dropdown">
<li><span>MENU1</span>
<ul>
<li><a href="#">MENU ITEM 1</a></li>
<li><a href="#">MENU ITEM 2</a></li>
</ul>
</li>
<li><span>MENU2</span>
<ul>
<li><a href="#">MENU ITEM 1</a></li>
<li><a href="#">MENU ITEM 2</a></li>
</ul>
</li>
<li><span>MENU3</span>
<ul>
<li><a href="#">MENU ITEM 1</a></li>
<li><a href="#">MENU ITEM 2</a></li>
</ul>
</li>
</ul>
CSS
Quote:
ul,li{margin:0;padding:0;}

#dropdown{
list-style-type: none;
margin:50px auto 0 auto;
text-align:center;
width: 303px;
}
#dropdown li{
background-color:#777;
border-right:1px solid #fff;
float:left;
height:25px;
line-height:25px;
width:100px;
}
#dropdown li > ul{
background-color:#777;
display:none;
height:52px;
list-style-type: none;
}
#dropdown li:hover > ul{
display: block;
}
#dropdown li:hover > ul li{
border-top: 1px solid #fff;
float:left;
height:25px;
}
#dropdown li:active > ul li{
border-top: 1px solid #fff;
float:left;
height:25px;
}
You can see this in use on my website navigation, where I've added a lot in the way of style to it, including border radii, background color changes and CSS3 transitions.

Hope some of you find this useful.

EDIT: Added :active pseudo-class to make it touch-friendly.
__________________
Ronald Roe
Small Business Web Design

Last edited by ronaldroe; 04-12-2011 at 02:47 AM. Reason: Now with with more touch-friendliness!!
ronaldroe is offline   Reply With Quote


Old 04-12-2011, 08:42 AM   #2
Gold Member
 
leroy30's Avatar
 
Join Date: Mar 2010
Location: Auckland, New Zealand
Posts: 326
Default

Hi ronaldroe,

Any chance you could elaborate on "EDIT: Added :active pseudo-class to make it touch-friendly" for us? I've never heard of this one before..
__________________
DVI web design | Portable Time Clock
leroy30 is offline   Reply With Quote
Old 04-12-2011, 01:56 PM   #3
Platinum Member
 
ronaldroe's Avatar
 
Join Date: Jan 2011
Location: Oklahoma City, OK
Posts: 676
Send a message via Skype™ to ronaldroe
Default

Quote:
Originally Posted by leroy30 View Post
Hi ronaldroe,

Any chance you could elaborate on "EDIT: Added :active pseudo-class to make it touch-friendly" for us? I've never heard of this one before..
Basically, I took a shot it the dark and copied the bit of code that makes the menu appear on hover, and changed :hover to :active. Turns out it works. On my website, when you tap "portfolio", at least on my iPhone, it opens the dropdown. Once I did that, I added it here so it would work for other people too. If you look at the last 2 blocks of the CSS, they're nearly identical, except the pseudo-class.
__________________
Ronald Roe
Small Business Web Design
ronaldroe is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 07:29 PM.


Camera Forum - Computer Forum - Web Design Forum

Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2012, vBulletin Solutions, Inc.
Content Relevant URLs by vBSEO 3.6.0 ©2011, Crawlability, Inc.