5
I have a select and I’m trying to change the color of it by selecting an option (for example I’m changing the color to red
). Using some attributes like hover
, focus
, active
and checked
i can even do what I want. The problem is that when select loses Focus it returns its original color.
I want the select to remain gray until it is selected and after the selected color red
be applied. Even if he loses focus after.
select {
color: gray;
}
select:hover,
select:focus,
select:active,
select:checked {
color: red;
}
select option {
color: #333;
}
option[value=""][disabled] {
display: none;
}
<select id="estado" name="estado">
<option value="" disabled selected>Selecione</option>
<option value="AC">AC</option>
<option value="AL">AL</option>
<option value="AM">AM</option>
<option value="AP">AP</option>
<option value="BA">BA</option>
<option value="CE">CE</option>
<option value="DF">DF</option>
<option value="ES">ES</option>
<option value="GO">GO</option>
<option value="MA">MA</option>
<option value="MG">MG</option>
<option value="MS">MS</option>
<option value="MT">MT</option>
<option value="PA">PA</option>
<option value="PB">PB</option>
<option value="PE">PE</option>
<option value="PI">PI</option>
<option value="PR">PR</option>
<option value="RJ">RJ</option>
<option value="RN">RN</option>
<option value="RO">RO</option>
<option value="RR">RR</option>
<option value="RS">RS</option>
<option value="SP">SP</option>
<option value="SC">SC</option>
<option value="SE">SE</option>
<option value="TO">TO</option>
</select>
I’ve never seen a method for
css
not dude. Ever thought of usingjs
?– Leonardo Rodrigues
Hi @Leonardorodrigues! com js would be easy! but here we only use to make the page dynamic or for more complex animations! all the rest of the styling we do using only css and Sass.
– alan