Home arrow Style Sheets arrow Page 2 - An Easy Way to Build Replacement Combo Boxes
STYLE SHEETS

An Easy Way to Build Replacement Combo Boxes


HTML forms offer certain challenges to the web designer. One of them is achieving a consistent style; not all elements are consistently styled across all browsers, and as a result you're faced with the possibility of losing some functionality if you choose not to use those elements. This article, the first of two parts, shows you how to use a single line text input field to recreate the functionality of select elements in a way that works across IE and FireFox.

Author Info:
By: Dan Wellman
Rating: 4 stars4 stars4 stars4 stars4 stars / 6
April 09, 2007
TABLE OF CONTENTS:
  1. · An Easy Way to Build Replacement Combo Boxes
  2. · Adding Some CSS
  3. · Styling the Text Input Field
  4. · Adding JavaScript

print this article
SEARCH DEVARTICLES

TOOLS YOU CAN USE

advertisement
An Easy Way to Build Replacement Combo Boxes - Adding Some CSS
(Page 2 of 4 )

Let's add some CSS now to get it looking like a combo box. In a new file in your text editor, add the following code:

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

This selector targets the drop-down arrow image and ensures that it is the correct size and has no margins or padding. Although I haven't done so in this example, you could easily use CSS to specify a second arrow image that could be used as a rollover, just to reinforce to visitors that it will do something when clicked. I think however that the functionality of combo boxes has been around long enough to be ingrained in the mind of pretty much any visitor, so they should assume that it will work in the same way as a standard combo box. Most visitors hopefully will not even have to think about it and will just assume it is an actual combo box, which is after all the intention behind the article.

Due to an inconsistency between IE and Firefox, the current code will line up the image correctly in FireFox, placing the image next to and inline with the text field. In IE however, the image is offset slightly. It's only a minor problem, but it does have an impact on how the page is viewed so should be corrected. We can do this with the following hack that targets IE 6 only:

* html body img.arrow {
 
position:relative;
 
top:-1px;
}

This is a well established hack for targeting IE 6 only with additional rules, sometimes referred to as the star hack. Whatever it's called, it works well in situations like this, but only works with IE 6. IE 7 will still display the image incorrectly. There is still a way to target IE 7 though, use:

*+ html body img.arrow {
 
position:relative;
 
top:-1px;
}


blog comments powered by Disqus
STYLE SHEETS ARTICLES

- CSS Combinators: Working with Child Combinat...
- CSS Combinators: Using General Siblings
- Intro to CSS Combinators
- CSS Semicircles and Web Page Headers
- Drawing Circular Shapes with CSS3 and Border...
- More CSS Pagination Link Templates
- CSS Pagination Links
- Animated CSS3 Image Gallery: Advanced Transi...
- CSS3 Animated Image Gallery: Transitions
- CSS3 Properties: Fixed Heights with box-sizi...
- CSS3 Properties: Altering Strokes and 3D Eff...
- CSS3 Properties: Text-Stroke
- CSS3 Transitions: Width and Height Properties
- Creating a Drop Down Menu in CSS3
- Intro to CSS Transitions

Dev Articles Forums 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Weekly Newsletter
 
Developer Updates  
Free Website Content 
Contact Us 
Site Map 
Privacy Policy 
Support 



© 2003-2012 by Developer Shed. All rights reserved. DS Cluster 4 - Follow our Sitemap
Popular Web Development Topics
All Web Development Tutorials