Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Style Select And Multiple Select?

How can I style both the <select> HTML tag, and the <select multiple="multiple"> HTML tag while both of the tags reside under a <form> tag? Of course styling within CSS. If someone knows how to accomplish this, may someone give me an example?

Thank you! Aaron

like image 338
Aaron Brewer Avatar asked Apr 06 '26 02:04

Aaron Brewer


1 Answers

You can use classes fairly easily:

.singleSelect {
  width: 200px;
}

.singleMultiple {
  width: 300px;
}

<form>
 <select class="singleSelect">
  <option>Test</option>
 </select>'
 <br/>
 <select class="singleMultiple" multiple="multiple">
  <option>Test 1</option>
  <option>Test 2</option>
  <option>Test 3</option>
 </select>
</form>

http://jsfiddle.net/GyxL4/

A more advanced selector may be used on the select[multiple], but beware, legacy browsers (EDIT: apparently only IE6) may not always support the attribute selector, and in the first example below, you're styling every SELECT element on the page (this is called an element selector):

select {
  width: 200px;
}

select[multiple] {
  width: 300px;
}

See: http://www.w3.org/TR/CSS2/selector.html

like image 187
Jared Farrish Avatar answered Apr 08 '26 17:04

Jared Farrish



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!