Html – Set tag’s size attribute through css

csshtmlhtml-select

Normally you can do this:

<select size="3">
    <option>blah</option>
    <option>blah</option>
    <option>blah</option>
</select>

And it would render as a selectionbox where all three options are visible (without dropping down)
I'm looking for a way to set this size attribute from css.

Best Answer

There ins't an option for setting the size, but if you do set the size some browsers will let you set the width/height properties to whatever you want via CSS.

Some = Firefox, Chrome, Safari, Opera.

Not much works in IE though (no surprise)

You could though, if you wanted, use CSS expressions in IE, to check if the size attribute is set, and if so, run JS to (re)set it to the size you want... e.g.

size = options.length;