【问题标题】:Add an icon for input type submit using IcoMoon使用 IcoMoon 为输入类型提交添加图标
【发布时间】:2018-05-19 00:03:00
【问题描述】:

我正在尝试使用 IcoMoon 将搜索图标添加到 <input type="submit">。我不能在<input> 中包含<i>

我尝试了以下使用伪元素:before的方法,但不起作用。

HTML:

<div class="top-search">
    <form class="navbar-form navbar-right">
        <input type="text" class="form-control" placeholder="Search...">
        <input type="submit" class="icon-search" value="e90e">
    </form>
</div>

CSS:

@font-face {
    font-family: 'icomoon';
    src: url('icomoon.eot?lkqd5y');
    src: url('icomoon.eot?lkqd5y#iefix') format('embedded-opentype'),
         url('icomoon.ttf?lkqd5y') format('truetype'),
         url('icomoon.woff?lkqd5y') format('woff'),
         url('icomoon.svg?lkqd5y#icomoon') format('svg');
    font-weight: normal;
    font-style: normal;
}

[class^="icon-"], [class*=" icon-"] {
    font-family: 'icomoon' !important;
    speak: none;
    font-style: normal;
    font-weight: normal;
    font-variant: normal;
    text-transform: none;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}
.icon-search:before {
    content: "\e90e";
}

【问题讨论】:

    标签: html css font-face


    【解决方案1】:

    &lt;input&gt; 元素不允许有伪内容。您可以改用&lt;button type="submit"&gt;。这样你就可以使用:before或者直接添加&lt;i&gt;标签。

    【讨论】:

    • 但最后我找到了这个&lt;input type="submit" class="icon-search" value="&amp;#xe90e"&gt; 并且它有效
    • 是的,这可能是另一种方法,关键是你不能在输入标签上使用伪元素。
    • yeai 需要知道上面可以用还是??因为我没有找到任何其他方法
    • 我认为它的工作方式是因为浏览器只是将&amp;#xe90e 呈现为图标字符,因为它有一个icon-search 类,它将font-family 设置为icomoon。在这种情况下,它不使用任何伪元素。
    【解决方案2】:

    我终于找到了解决上述问题的方法

    <input type="submit" class="icon-search" value="&#xe90e">
    

    【讨论】:

      猜你喜欢
      • 2014-01-15
      • 2017-02-28
      • 1970-01-01
      • 2023-03-10
      • 1970-01-01
      • 1970-01-01
      • 2011-12-17
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多