Combo & List Boxes

HTML uses the same construct, <select>...</select>, for creating combo boxes and list boxes. List boxes are created by specifying a value, greater than 1, for the size attribute for the select tag. The default value of unity causes a combobox to be displayed. Here is the code used to generate the example above

<select size="1">
    <optgroup label="Europe">
        <option>United Kingdom</option>
        <option>Luxembourg</option>
    </optgroup>    
    <optgroup label="Asia">
        <option>India</option>
        <option>Dubai</option>
    </optgroup>
</select>

Uncheck the Listbox checkbox to view the example as a combobox. There appears to be a bug in Opera that causes the select control to become unresponsive to script driven changes in its size unless the empty attribute setting code multiple="" is supplied or the initial size specification is greater than unity.

The optgroup element is used to group options that form a logical group. CSS styling applied to this element is inherited by its contained option elements. It is possible to use optgroup without assigning its label attribute as a shorthand way to style the contained option entries. Note that optgroups cannot be nested. In addition to generic attributes there are a small number that are specific to the select family of HTML elements.

The default rendition of selects in all three browsers has a hopelessly dated feel to it. This can be remedied to a certain extent by assigning the CSS background-color attribute. However, this still leaves the scrollbar with its normal Windows color settings. In our view attempting to create CSS + HTML scrollbars is a rather futile exercise. One runs into such efforts quite regularly while browsing the net and without a single exception they all sacrifice useability for appearance - never a good compromise. There is nothing wrong with having default Windows colors for scrollbars - the one you are seeing on the extreme right of this page is a case in point:it is familiar and easy to use. The expand arrow button in combobox mode cannot be styled either but there is a relatively simple workaround to the problem which we have used on this site. It is described here.

Jump To...

Colophon