1

I made select-option. But option:hover does not work. How can I fix it or what do you prefer? Style must be like this

My codes

 <select>
      <optgroup label="Yaşayış üçün">
        <option>Yeni tikili</option>
        <option>Köhnə tikili</option>
      </optgroup>
      <optgroup label="Ticarət obyekti">
        <option>Yeni tikili</option>
        <option>Köhnə tikili</option>
      </optgroup>
    </select>

My styles Css

select {
  height: 48px;
  border: 1px solid #cbd5e1;
  box-sizing: border-box;
  border-radius: 8px;
  margin-top: 8px;
  padding: 12px 16px;
}

optgroup {
  padding: 16px;
  background: #f1f5f9;
}

option {
  background-color: white;
}

option:hover {
  background: #dbeafe;
}

aynber
  • 22,380
  • 8
  • 50
  • 63
Rahil Ali
  • 276
  • 1
  • 15
  • Styling for those base elements is very limited. Anything you put in CSS is going to be ignored by the browser. You would need to build your own select menu using custom js and css classes and either integrate them with the and
  • . See the most recent answer here: https://stackoverflow.com/questions/7208786/how-to-style-the-option-of-an-html-select-element?answertab=modifieddesc#tab-top or https://www.w3schools.com/howto/tryit.asp?filename=tryhow_custom_select
  • – AStombaugh Apr 21 '22 at 17:39
  • @AStombaugh I used w3school codes. But another problem is that optgroup does not work – Rahil Ali Apr 21 '22 at 17:47
  • If you read the entirety of the link I posted you can find that adding `
  • ` and `
  • ` can cosmetically divide your options into groups – Crimp Apr 21 '22 at 17:54
  • @RahilAli is just as limited as the other tags. See the links I've provided as well as the links in the answers below for the workarounds. – AStombaugh Apr 21 '22 at 17:56