简体   繁体   English

设置html选择菜单的样式

[英]styling a html select menu

i am trying to change the icon of a html select menu using fontawesome icon fonts. 我正在尝试使用fontawesome图标字体来更改html选择菜单的图标。 My code is as follows 我的代码如下

<select>
    <option value="1">1</option>
    <option value="2">2</option>
    <option value="3">3</option>
    <option value="4">4</option>
</select>

my css is 我的CSS是

select {
    position: relative;
}
 select:after {
    font-family: 'FontAwesome';
    content: '\F150';
    position: absolute;
    color: black;
}

here is the demo 这是演示

how do i do this? 我该怎么做呢? could someone please help me.. 有人可以帮我吗..

It has something to do with how browsers render select. 它与浏览器如何呈现选择有关。

You need to put a label for the select, then put your css after the label 您需要为选择贴上标签,然后在标签后贴上CSS

<select id="select-1" name="select-1"> ... </select> <label for="select-1"></label>

then in css 然后在CSS

#select-1 + label:after { styling }

http://jsfiddle.net/YdQka/9/ http://jsfiddle.net/YdQka/9/

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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