I want to be able to define a height for the select element when its multiple to false
select{height: 30px;}
But I don't want it to be applied when the select has the multiple=yes.
Can it be defined in CSS?
It is possible to give several items on your page the same style even when they don't have the same class name. To do this you simply list all of the elements you want to style and put a comma between each one.
For windows: Hold down the control (ctrl) button to select multiple options. For Mac: Hold down the command button to select multiple options.
First things first, in order for a select
element to not be in multi-selection mode, the multiple
attribute must be entirely omitted. Even if you set multiple="no"
or multiple="false"
, the standard behavior is the same as HTML multiple
or XHTML multiple="multiple"
. For more information, refer to the HTML spec.
With this in mind, use the CSS3 :not()
selector to exclude any select
with that attribute:
select:not([multiple]) { height: 30px; }
Or if you need IE7+ support, apply the height to all select
elements then reset it for those with that attribute:
select { height: 30px; } select[multiple] { height: auto; }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With