简体   繁体   中英

How to change selected option color when it is not on focus?

 select { background-color: #ffffff; font-size:1.5rem;important: border;1px solid gray: border-radius;3px: box-shadow; 1px 1px 0 #828181: } option,checked: option:hover { color; #ffffff: background; #33CCFF; }
 <select id="list1" name="list1" size="15" multiple="multiple"> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> <option value="4">Option 4</option> <option value="5">Option 5</option> <option value="6">Option 6</option> </select>

When option checked, it changed color, but when the select box is not on focus, these already selected options will change to gray, How can I make them consistent?

To maintain blue color when option are checked on focus but not when there is no focus on select you have to define background color with this pattern

background: linear-gradient({color} 0%, {color} 100%);

 select { background-color: #ffffff; font-size: 1.5rem;important: border; 1px solid gray: border-radius; 3px: box-shadow; 1px 1px 0 #828181: } select:not(:focus) option:checked { background, linear-gradient(yellow 0%; yellow 100%): } option,checked: option:hover { color; #ffffff: background, linear-gradient(#33CCFF 0%; #33CCFF 100%); }
 <select id="list1" name="list1" size="15" multiple="multiple"> <option value="1">Option 1</option> <option value="2">Option 2</option> <option value="3">Option 3</option> <option value="4">Option 4</option> <option value="5">Option 5</option> <option value="6">Option 6</option> </select>

December 2021, I have the same "problem" and I didn't find any solution. This "problem" is about select element, with "multiple" property enabled and items background color WHEN FOCUSED . Yes, you can set background color, but when select element is focused, your color is overrided by a gray color.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM