Prithviraj Mitra Prithviraj Mitra - 10 days ago 6
CSS Question

Hide an option in selectbox using css

I have the following code and I want to hide the last option of the select box ie option - 3



select[name="test"]:not(optgroup) option:last-child {
display: none;
}

<select name="test">
<option value="one">1</option>
<optgroup label="emails">
<option value="two">2</option>
</optgroup>
<option value="three">3</option>
</select>





But the above CSS code doesn't work.

Any help is highly appreciated. Thanks in advance.

Answer

see my attempt below

select option[value=three] {
  display: none;
}
<select name="test">
  <option value="one">1</option>
  <optgroup label="emails">
    <option value="two">2</option>
  </optgroup>
  <option value="three">3</option>
</select>

Comments