Style Sheets
  Home arrow Style Sheets arrow Page 2 - Taming the Select
Dev Articles Forums 
ADO.NET  
Apache  
ASP  
ASP.NET  
C#  
C++  
ColdFusion  
COM/COM+  
Delphi-Kylix  
Design Usability  
Development Cycles  
DHTML  
Embedded Tools  
Flash  
Graphic Design  
HTML  
IIS  
Interviews  
Java  
JavaScript  
MySQL  
Oracle  
Photoshop  
PHP  
Reviews  
Ruby-on-Rails  
SQL  
SQL Server  
Style Sheets  
VB.Net  
Visual Basic  
Web Authoring  
Web Services  
Web Standards  
XML  
Dedicated Servers  
Moblin 
JMSL Numerical Library 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
STYLE SHEETS

Taming the Select
By: Chris Heilmann
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 16
    2004-11-15

    Table of Contents:
  • Taming the Select
  • DOM to the rescue
  • But wait, there is more!
  • The Script

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Taming the Select - DOM to the rescue


    (Page 2 of 4 )

    What we can style nicely are JavaScript drop-downs. We can have a link that shows and hides a list of links in an accessible manner (off-left). The only problem is that we make ourselves dependent on JavaScript, something we must avoid at all costs.

    By using DOM JavaScript we can replace the original SELECT with a style-able and accessible drop-down, one that only appears if the browser can handle it.

    This script does that. It grabs every SELECT in the document with the class turnintodropdown and replaces it with a styleable CSS dropdown. In essence, it replaces the SELECT with a new DIV. This DIV contains a hidden field has the same name and id as the original SELECT. Furthermore the script creates a list of links that get populated from the OPTION data and a link that shows and hides this list when being clicked on. Clicking one of the links in the list will populate the hidden field with the current value, set it as the text of the "hide and show" link and hide the list.

    To see it in action, check the example page.

    The style of the drop-down is defined in some classes that get applied via the script as needed:

    • dropcontainer - Defines the parent element of the newly created drop-down parent (a DIV). This needs to be set to "position:relative" to position the drop-down.

    • trigger - Defines the look of the link when then drop-down is hidden.

    • activetrigger - Defines the look of the link when then drop-down is shown.

    • dropdownhidden - Defines the look of the generated drop-down (a UL) when it is hidden.

    • dropdownvisible - Defines the look of the generated drop-down when it is hidden.

    Check the CSS embedded in the example page for one possible solution.

    You can change the class names in the variable section at the top of the script.

    More Style Sheets Articles
    More By Chris Heilmann


       · I would be glad to get any feedback from Mac users on this technique, as I cannot...
       · As far as I remember Mac Firefox didn't have a problem.The problem I have with...
     

    STYLE SHEETS ARTICLES

    - Creating Three-Column Web Page Layous with N...
    - Swapping Column Positions in Web Page Layout...
    - Creating Web Page Layouts with Negative Marg...
    - Creating Gradients for Individual Containers...
    - Creating Gradients for Web Page Headers with...
    - SEO Scrolling Frames Problem Solved
    - Building Cross-Browser Background Effects wi...
    - CSS: Pseudo
    - Using PNG Images to Build Background Effects
    - CSS: Continuing the Clarification of CSS Cla...
    - CSS: Top Secret Classification
    - CSS: Dimensions
    - CSS: Margins and Padding
    - CSS: Crossing the Border
    - CSS: Text, Fonts, and Tables







    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway