|
|
|
168 days, 8 hours, 50 minutes
ago
Wednesday, September 30, 2009 3:41:38 PM
GMT
Tuesday, September 29, 2009 8:40:45 PM
GMT
|
|
www.jankoatwarpspeed.com --
For me, standard HTML Select element is pretty much annoying. It's ugly. It can't be styled properly in Internet Explorer. And it can't contain nothing but simple text. That is the reason why I needed to reinvent Drop Down element. This tutorial shows how to do that (easily, believe it or not).
View demo Download source code
There is an update at the end of this tutorial and the second demo that shows the results of this updated code.
Simple structure
Let me explain HTML structure that will be used here. In this example we will use a short list of 8 countries. List is created using Definition List (DL) element. Why this element? It is similar to unordered/ordered list - the only difference is that DL consists of two elements: DT (term) and DD (definition). This makes it perfect candidate for Drop Down element. Element DT can be used to show collapsed state with currently selected option while DD can show all the available options in nested UL. Here is the sample structure:
Please select the country
Brazil
France
Germany
India
Japan
Serbia
United Kingdom
United States
In order to make Drop Down functional we have to add several important CSS styles. First of all we have to reset margins and paddings for DD, DT and UL. DD will be positioned relatively, so that nested UL can be absolutely positioned. As I mentioned earlier, in collapsed state, only DT will be visible. It contains link with span inside it and two elements make sliding doors, a technique that is often used for creating buttons and tabs. Styling UL is simple, it will be positioned 2px below DT and initially hidden.
/* General dropdown styles */
.dropdown dd, .dropdown dt, .dropdown ul { margin:0px; padding:0px; }
.dropdown dd { position:relative; }
/* DT styles for sliding doors */
.dropdown dt a {background:#e4dfcb url(arrow.png) no-repeat scroll right center;
display:block; padding-right:20px;
|
|
tags:
Tutorials
|
|
No comments yet, be the first one to post comment.