Style Sheets
  Home arrow Style Sheets arrow Page 3 - An Easy Way to Build Replacement Combo Box...
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  
Mobile Linux 
App Generation ROI 
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

An Easy Way to Build Replacement Combo Boxes
By: Dan Wellman
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 4
    2007-04-09

    Table of Contents:
  • An Easy Way to Build Replacement Combo Boxes
  • Adding Some CSS
  • Styling the Text Input Field
  • Adding JavaScript

  • 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


    An Easy Way to Build Replacement Combo Boxes - Styling the Text Input Field


    (Page 3 of 4 )

    So now both of the most popular versions of IE are behaving. Next we can style the text input field:

    .combo {
     
    height:20px;
     
    width:140px;
     
    color:#000000;
     
    border-style:solid;
     
    border-width:1px 0px 1px 1px;
     
    border-color:blue;
     
    margin:0px;
     
    padding:0px;
     
    vertical-align:bottom;
    }

    The height is set to the same as the image and the width is long enough to display each of the options in full. It is given the same border values, with the exception of missing off the right-hand border, as this will be flush with the image anyway. The div containing the options will need to be hidden for now, and will only be shown when the drop-down arrow image is clicked (exactly like a standard combo box). This CSS for this would be as follows:

    #combodiv {
     
    padding:0px;
     
    display:none;
     
    position:relative;
     
    left:151px;
     
    height:150px;
     
    width:120px;
     
    border-style:solid;
     
    border-width:0px 1px 1px 1px;
     
    border-color:blue;
     
    background-color:white;
     
    overflow-y:auto;
     
    overflow-x:hidden;
    }

    The rule display:none ensures that the div is initially hidden from view. Everything else should make sense without explanation, but I feel I should add that the overflow rules break the validity of the CSS. The overflow rule alone is fine, but specifying x and y is not; however, without these rules, FireFox and IE will display a horizontal scroll bar as well as a vertical scroll bar, which frankly ruins the appearance completely.

    One way around this would be to not have any scroll bars at all (by specifying overflow:hidden). The good thing about the vertical scroll bar is that we don't need to adjust the height of the options div if there are more than about six options. The bad thing is that we end up with another element that can't be consistently styled across browser platforms. However, vertical scroll bars shouldn't really be styled at all anyway, and the scroll bar is only visible while the options div is open. I'll leave it up to you to decide whether to use the non-valid CSS and user friendly scroll bar, or valid CSS with no scroll bar. Finally, we can add some styling to the options themselves:

    .option {
     
    display:block;
     
    text-decoration:none;
     
    font-family:arial, sans-serif;
     
    color:#000000;
     
    width:100%;
    }

    .option:hover {
     
    background-color:blue;
     
    }

    So what do we have here? Nothing much in all honesty! The options are links, so they need to have their underlining removed (as they aren't functioning as traditional links would). The display:block rule lays the options out nicely so that they appear more like an unordered list. Without this, the elements follow each other one after the other. Setting the width to 100% is used more in the hover psuedoclass rule and ensures that the colored background, which marks the rollover, stretches the full width of the div. Save the file as combo.css.

    More Style Sheets Articles
    More By Dan Wellman


       · Hello All,This article shows a very quick and easy way to implement custom...
     

    STYLE SHEETS ARTICLES

    - Improving the Visual Presentation of a CSS D...
    - Fixing Browser Incompatibilities in a CSS Dr...
    - Building Clean Drop-Down Menus with CSS
    - Creating Hybrid Web Page Layouts with Negati...
    - 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






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