Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS for element SELECT multiple=yes

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?

like image 639
Yannick Avatar asked Nov 18 '11 20:11

Yannick


People also ask

Can I select multiple elements at once with 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.

How do I select multiple options from a drop down list in HTML CSS?

For windows: Hold down the control (ctrl) button to select multiple options. For Mac: Hold down the command button to select multiple options.


1 Answers

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; } 
like image 190
BoltClock Avatar answered Nov 10 '22 00:11

BoltClock