I am trying to build a custom select option list using vanilla HTML and CSS.
From basic Googling, I understood those option elements are rendered by the OS, not HTML and thus cannot be custom styled.
But I could not find a good explanation of how that affects its ability to be custom styled.
Also, this is for an angular CLI project I am working on. I understand there are workarounds for this shortcoming where the select list is replaced by a ul li list. Also, there are a few angular plug-ins out there that can be used for customized dropdowns.
select {
-webkit-appearance: none;
-moz-appearance: none;
appearance: none;
padding: 0.25rem 2rem 0.25rem 0.5rem;
outline: none;
font-size: 14px;
letter-spacing: 0;
line-height: 22px;
background: url(https://cdn.sstatic.net/Sites/stackoverflow/img/apple-touch-icon@2.png) 96% / 20% no-repeat;
}
select:hover {
border: 1px solid #7d7873;
background: url(https://i.stack.imgur.com/CE5lz.png) 96% / 20% no-repeat;
}
select:active {
border: 1px solid #0496bb;
background: url(https://i.stack.imgur.com/CE5lz.png) 96% / 20% no-repeat;
}
/* cannot custom style this */
option:hover {
background: #0496bb;
}
option {
background: yellow;
}
select::-ms-expand {
display: none;
/* remove default arrow on ie10 and ie11 */
}
<h2>
Custom option hover in select list
</h2>
<select #selectTest>
<option>Gryffindor</option>
<option selected>Ravenclaw</option>
<option>Hufflepuff</option>
<option>Slytherin</option>
</select>