2

I have a select[multiple] attribute with many options

<option value="85" data-select2-id="38">dolcevita</option><option value="22" data-select2-id="4">a</option><option value="6" data-select2-id="5">aa</option><option value="78" data-select2-id="6">aaaa</option>...<option value="28" data-select2-id="7">ad2</option>

the options are random, there can be many options

How can I apply the same css style to all those select[multiple] options?

<select multiple />
  <option>example1</option>
   ...
</select>

looked to apply styles something like this to all my options:

style css

 select[multiple] > option{
    background: red;
    color: black;
    ...
 }
Samuel D.
  • 199
  • 10
  • 2
    What's wrong with `select[multiple] > option`? – IT goldman Sep 22 '22 at 21:55
  • The CSS example does work for the select[multiple]. I would suggest getting rid of the / in your select though since the /select tag ends the select, although that doesn't affect anything. – imvain2 Sep 22 '22 at 21:58
  • https://stackoverflow.com/questions/30187570/styling-selected-option This solved my issue thanks to bloodyKnuckles – Samuel D. Sep 22 '22 at 23:23

1 Answers1

0

All you have to do, it's to disable the browsers default styles

.disable-select {
    user-select: none; /* supported by Chrome and Opera */
   -webkit-user-select: none; /* Safari */
   -khtml-user-select: none; /* Konqueror HTML */
   -moz-user-select: none; /* Firefox */
   -ms-user-select: none; /* Internet Explorer/Edge */
}

then call that class into your select tag

<select class="disable-select">
<option>Hello</option>
</select>

now you can make your styles

KroKing
  • 57
  • 7
  • I'm so sorry mate, it keeps giving me the same error, the solution that @bloodyKnuckles published of another similar doubt was that it helped me to solve it – Samuel D. Sep 22 '22 at 23:21