Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Styling selected option [duplicate]

Tags:

html

css

Pretty self explaining, I need to style the option that is selected by the user. Is this possible without javascript?

Simple example:

HTML:

<select multiple>
    <option class="opt1" value="">Option 1</option>
    <option class="opt2" value="">Option 2</option>
</select>

CSS:

.opt1[selected]{
    background-color: red;
}
.opt2{
    background-color: green;
}

JS Fiddle Example

like image 656
AlexG Avatar asked May 12 '15 10:05

AlexG


1 Answers

try this .

.your-select option:checked {
    background:#333;padding:20px;width:100px;border:3px solid #F00
}
<select multiple class="your-select">
    <option class="opt1" value="">Option 1</option>
    <option class="opt2" value="">Option 2</option>
 </select>
like image 68
Danin Na Avatar answered Oct 19 '22 20:10

Danin Na