CSS 使用 font-awesome 自定义选择

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30782605/
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-30 11:16:39  来源:igfitidea点击:

Customize a select with font-awesome

cssselectfont-awesome

提问by teamo

This is what I have actually:

这就是我实际拥有的:

HTML

HTML

<label class="select">
  <select name="email" id="email">
    <option>aaaa</option>
    <option>aaaa</option>
    <option>aaaa</option>
    <option>aaaa</option>
    <option>aaaa</option>
    <option>aaaa</option>
  </select>
</label>

CSS

CSS

.cforms select {
    -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;   
}


.select {
    position:relative;   
    display: -moz-inline-stack;
    display: inline-block;
    vertical-align: middle;
    zoom: 1;
    *display: inline;
    margin-top:40px;
}

.select:after {
  content: "\f0dc";
  font-family: FontAwesome;
  color: #000;
  padding:8px;
  position:relative;
  right:35px;
  top:0px;
  background:red;
  z-index:-1;
  width:10%;
  line-height:10%;
}

Problem

问题

Actually, no arrows appears near my select.

实际上,我的选择附近没有出现箭头。

Could you please help me with this.

你能帮我解决这个问题吗?

I searched on the web for examples, but I can't make it works.

我在网上搜索了例子,但我不能让它工作。

Thanks.

谢谢。

回答by Dmitriy

maybe so

可能是吧

.select {
    border: 1px solid #ccc;
    overflow: hidden; 
    height: 40px;    
    width: 240px;
    position: relative;
    display: block;
}

select{       
    height: 40px;
    padding: 5px;
    border: 0;
    font-size: 16px;       
    width: 240px;
   -webkit-appearance: none;
    -moz-appearance: none;
    appearance: none;
}
.select:after {
    content:"\f0dc";
    font-family: FontAwesome;
    color: #000;
    padding: 12px 8px;
    position: absolute; right: 0; top: 0;
    background: red;
    z-index: 1;
    text-align: center;
    width: 10%;
    height: 100%;      
    pointer-events: none;
    box-sizing: border-box;   
}
<link href="http://maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css" rel="stylesheet"/>
<label class="select">
    <select name="email" id="email">
        <option>aaaa1</option>
        <option>aaaa2</option>
        <option>aaaa3</option>
        <option>aaaa4</option>
        <option>aaaa5</option>
        <option>aaaa6</option>
    </select>
</label>