CSS 样式选择下拉框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17516559/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 23:26:10  来源:igfitidea点击:

Styling Select Drop down box

css

提问by user2516043

I have a HTML Select drop down box, which I have styled, the problem I am having is that I can not seem to style the background color of the options. Below is a link to a demo as you can see the drop down options has a white background, which i am trying to change.

我有一个 HTML Select 下拉框,我已经对其进行了样式设置,但我遇到的问题是我似乎无法设置选项的背景颜色的样式。下面是演示的链接,因为您可以看到下拉选项具有白色背景,我正在尝试更改。

http://cssdeck.com/labs/lnroxrua

http://cssdeck.com/labs/lnroxrua

Here is my HTML Code:

这是我的 HTML 代码:

<div class="select-div">
    <select name="pagination">

      <option value="10" selected="selected">10</option>
      <option value="20">20</option>
      <option value="30">30</option>
      <option value="40">40</option>
      <option value="50">50</option>
    </select>
    </div>

CSS Styling

CSS 样式

  select{
    background:transparent;
    width: 170px;
    padding: 2px;
    font-family:Arial, Helvetica, sans-serif;
    font-size:11px;
    font-weight:600;
    color:#fff;
    line-height: 1;
    border: 0;
    border-radius: 0;
    height: 22px;
    -webkit-appearance: none;

    }

    .select-div{
width: 170px;
height: 22px;
overflow: hidden;
background: url(arrowhead.png) no-repeat right #363636;
border-top:#575757 1px solid;
-webkit-border-radius: 4px 4px 4px 4px;
 -moz-border-radius: 4px 4px 4px 4px;
      border-radius: 4px 4px 4px 4px;
-webkit-box-shadow: inset 0 2px 4px rgba(107, 105, 105, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
 -moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
      box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15), 0 1px 2px rgba(0, 0, 0, 0.05);
      -moz-box-shadow:    0px 8px 3px -9px #000000;
      -webkit-box-shadow: 0px 8px 3px -9px #000000;
      box-shadow:         0px 8px 3px -9px #000000;
   }

Thanks

谢谢

回答by leoMestizo

Here's a DEMO.

这是一个演示

Just add this CSS rule:

只需添加此 CSS 规则:

select > option {
   background: color;
}

For example:

例如:

select > option {
   background: pink; /* Or an hexadecimal value */
}

Cheers, Leo!

加油,里奥!

回答by mr.T

Unfortunately, webkit browsers do not support styling of tags yet.

不幸的是,webkit 浏览器还不支持标签样式。

check: How to style a select tag's option element?

检查: 如何设置选择标签的选项元素的样式?