javascript - change browser's blue default color when selecting an option element in a select element - Stack Overflow

I know how to change the color of the background of the options element, and also the hover.What I'

I know how to change the color of the background of the options element, and also the hover.

What I'm trying to do is to change the default browser's color (blue in chrome) when you click over an option element, and while the "select" is still on focus.

I made this pen:

-------------------------------HTML --------------------------------

<select size="3" name='options' multiple>
   <option value='option-1' class="options">Option 1</option>
   <option value='option-2' class="options">Option 2</option>
   <option value='option-3' class="options">Option 3</option>
</select>  

<p>
   Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure suscipit 
   eos hic voluptatibus ratione impedit ullam sequi, delectus rem. Corporis nemo 
</p>

-------------------------------CSS---------------------------------------

select{
 border-radius:.5em;
 width:200px;
 height:100px;
}

::selection {
  background: #ffb7b7;
}

::-moz-selection {
  background: #ffb7b7; 
}

*:focus {
outline: #ffb7b7 solid 5px; 
}

I'd like to make the blue default color a #ffb7b7 like the outline and the text selection.

Thanks in advance!

I know how to change the color of the background of the options element, and also the hover.

What I'm trying to do is to change the default browser's color (blue in chrome) when you click over an option element, and while the "select" is still on focus.

I made this pen:

http://codepen.io/dieggger/pen/QbRZXP

-------------------------------HTML --------------------------------

<select size="3" name='options' multiple>
   <option value='option-1' class="options">Option 1</option>
   <option value='option-2' class="options">Option 2</option>
   <option value='option-3' class="options">Option 3</option>
</select>  

<p>
   Lorem ipsum dolor sit amet, consectetur adipisicing elit. Iure suscipit 
   eos hic voluptatibus ratione impedit ullam sequi, delectus rem. Corporis nemo 
</p>

-------------------------------CSS---------------------------------------

select{
 border-radius:.5em;
 width:200px;
 height:100px;
}

::selection {
  background: #ffb7b7;
}

::-moz-selection {
  background: #ffb7b7; 
}

*:focus {
outline: #ffb7b7 solid 5px; 
}

I'd like to make the blue default color a #ffb7b7 like the outline and the text selection.

Thanks in advance!

Share Improve this question asked Aug 19, 2015 at 15:05 Diego MontesDiego Montes 431 silver badge6 bronze badges
Add a ment  | 

1 Answer 1

Reset to default 5

Ok, I played with your codepen and found this solution :

option:checked {
    box-shadow: 0 0 10px 100px #ffb7b7 inset;
}

I added this code in your CSS. It seems that box-shadow replaces the browser color so it works :) (tested on Firefox, Chrome 44)

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745190480a4615840.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信