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.
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:
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:
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.