简体   繁体   English

如何在选择中正确使用 fontawesome

[英]How to use correctly fontawesome in select

I'm trying to show the fontawesome icons in a select, but in the drop-down list the icons are not previewed well我试图在选择中显示字体很棒的图标,但在下拉列表中图标预览效果不佳

 .FontAwesomeSelect { font-family: Font Awesome\\ 5 Free; font-size: 18px; }
 <link href="https://use.fontawesome.com/releases/v5.0.6/css/all.css" rel="stylesheet"/> <select name="sample" id="sample" class="FontAwesomeSelect"> <option value="">----</option> <option value="fa fa-address-card">&#xf2bb;</option> <option value="fa fa-bell">&#xf0f3;</option> <option value="fa fa-bookmark">&#xf02e;</option> <option value="fa fa-building">&#xf1ad;</option> </select>

结果:

You don't need the FontAwesomeSelect class.您不需要FontAwesomeSelect类。 Instead, use the default fa class.相反,使用默认的fa类。

<select name="sample" id="sample" class="fa">
        <option value="">----</option>
        <option value="fa fa-address-card">&#xf2bb;</option>
        <option value="fa fa-bell">&#xf0f3;</option>
        <option value="fa fa-bookmark">&#xf02e;</option>
        <option value="fa fa-building">&#xf1ad;</option>
</select>

Fiddle : https://jsfiddle.net/JonathanParentLevesque/uwe8azo7/4/小提琴https : //jsfiddle.net/JonathanParentLevesque/uwe8azo7/4/

Demo font-awesome 5 in a drop-down list

Notice well what contains this class:请注意包含此类的内容:

来自 Google Chrome 控制台的字体很棒的 CSS

If it's still not working, try this:如果它仍然无法正常工作,请尝试以下操作:

.fa option {

    font-weight: 900;
}

using the previous example i did this使用前面的例子我做了这个

<select name="sample" id="sample" class="fa">
    <option value="">----</option>
    <option value="fa fa-address-card">&#xf2bb;</option>
    <option value="fa fa-bell">&#xf0f3;</option>
    <option value="fa fa-bookmark">&#xf02e;</option>
    <option value="fa fa-building">&#xf1ad;</option>

And add this custom css并添加这个自定义css

select.form-control.fa option{ font-weight: 900; }

working with font awesome 5.6.3使用字体真棒 5.6.3

<style>
    .fa option {
    font-weight: 900;
    }
</style>

Then the options can look like this:然后选项看起来像这样:

<option class="fa" value="select_value">&#xf0f3; Name Of Select</option>

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

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