【问题标题】:How to style the arrow of a select element [duplicate]如何设置选择元素的箭头样式[重复]
【发布时间】:2015-12-29 06:51:15
【问题描述】:

如何更改<select> 中的箭头样式。更改背景、字体颜色或所有边框内容很简单,但如何更改“箭头”?当我更改字体颜色时,内容颜色发生了变化,但箭头保持黑色。

.language-choice{
    margin-top: 10px;		
    color: #719dd1;
    border-color: #719dd1; 
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border-width: 2px;
}
<select class="language-choice">
    <option value="en">English</option>
    <option value="pl">Polish</option>
</select>

【问题讨论】:

  • JSF 在这个问题的上下文中只是一个 HTML 代码生成器。当您只显示负责生成 HTML/CSS 输出的服务器端代码时,HTML/CSS 专家不会知道您在说什么。只需立即显示生成的 HTML/CSS 输出(当然是 MCVE 风格)。我为您重新构建了这个问题,以便 HTML/CSS 专家更容易回答。一旦你得到答案,那么只需重写服务器端代码(在你的例子中是 JSF),这样它就可以准确地产生所需的 HTML/CSS 输出。
  • 箭头的样式取决于浏览器和操作系统。检查此链接以替换默认链接。 cssdeck.com/labs/styling-select-box-with-css3

标签: html css select


【解决方案1】:

你可以试试这个:

  .language-choice{
     width: 268px;
    padding: 5px;
    font-size: 16px;
    line-height: 1;
    border: 0;
     border-color: #719dd1; 
   -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border-width: 2px;
    height: 34px;
    background: url(http://cdn1.iconfinder.com/data/icons/cc_mono_icon_set/blacks/16x16/br_down.png) no-repeat right #ddd;
    -webkit-appearance: none;
   -moz-appearance:    none;
   appearance:         none;
    background-position-x: 244px;
}

DEMO FIDDLE

【讨论】:

【解决方案2】:

你可以这样尝试-

.selectWrap{
    position: relative;
    width: 100px;
}
.language-choice{
    /*margin-top: 10px;*/ 
    color: #719dd1;
    border-color: #719dd1; 
    -webkit-border-radius: 5px;
    -moz-border-radius: 5px;
    border-radius: 5px;
    border: 2px solid #ccc;
    padding: 5px;
    width: 100%;
    -webkit-box-sizing: border-box;
       -moz-box-sizing: border-box;
            box-sizing: border-box;

}
span{
    background: url('http://www.symantec.com/images/version-3/arrows/info-box-triangle-icon.png') #fff no-repeat center center / 13px 10px;
    height:13px;
    width: 25px;
    position: absolute;
    height: calc(100% - 4px);
    right: 2px;
    top:2px;
    border-radius: 0 3px 3px 0;
    pointer-events:none;
}
    <div class="selectWrap">
    <span></span>
        <select class="language-choice">
            <option value="en">English</option>
            <option value="pl">Polish</option>
        </select>
    </div>

【讨论】:

    猜你喜欢
    • 2019-03-29
    • 2020-11-05
    • 2014-02-05
    • 2011-11-04
    • 2021-06-13
    • 2023-03-29
    • 1970-01-01
    • 2020-12-10
    相关资源
    最近更新 更多