【问题标题】:Font awesome icon on search box won't appear [duplicate]搜索框上的字体真棒图标不会出现[重复]
【发布时间】:2019-02-14 15:57:43
【问题描述】:

我试图使用 font awesome 并将其放在搜索框中。

我用的是ff html:

<form class="form-inline my-2 my-lg-0">
    <input
      class="form-control mr-sm-2 search"
      type="search"
      placeholder="Search.."
      aria-label="Search"
    />
</form>

然后为了控制搜索的布局,我放置了 ff CSS:

input.form-control.mr-sm-2.search{
    outline: none;
    border: none;
    font-size: 12px;
    border-radius: 2px;
    position: relative;
}



input.form-control.mr-sm-2.search:before{
    content: "\f002";
    font-family: 'FontAwesome';
    font-style: normal;
    font-weight: normal;
    text-decoration: inherit;
    color: #000;
    font-size: 13px;
    padding-right: 15px;
    position: absolute;
    top: 15px;
    left: 0;
}

知道为什么字体真棒图标不起作用吗?

【问题讨论】:

标签: html css


【解决方案1】:

您是否按 F12 检查并查看控制台选项卡?可能是您缺少字体文件和图像文件。 您应该使用 CDN 链接:

<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">

【讨论】:

【解决方案2】:

我检查了一些,以下可以帮助你。

Put a font-awesome icon inside an input tag

试试这个

【讨论】:

    【解决方案3】:

    :before 或其他伪类不适用于 &lt;br/&gt;&lt;img /&gt;&lt;input /&gt; 标签等自闭合元素

    你可以这样做

    .search-wrap{
      position: relative;
      border: 1px solid #ccc;
      padding: 10px;
      border-radius: 5px;
      max-width: 200px;
    }
    .search-wrap input{
      border: 0px;
      padding-left: 20px;
    }
    .search-wrap i.fa{
      position: absolute;
      left: 10px;
      top:10px;
    }
    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.1.0/css/font-awesome.min.css" rel="stylesheet">
    
    <div class="search-wrap">
      <input class="form-control" type="text" Placeholder="Search here.." />
      <i class="fa fa-search"> </i>
    </div>

    【讨论】:

      【解决方案4】:

      它没有显示,因为 ::after::before[伪元素] 仅在包含元素中定义时才有效。阅读W3Cspecifications

      【讨论】:

        猜你喜欢
        • 2013-09-30
        • 2017-10-04
        • 2013-08-23
        • 1970-01-01
        • 2018-05-18
        • 2020-04-21
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多