【问题标题】:Font Awesome i css [duplicate]字体真棒我的CSS [重复]
【发布时间】:2015-05-06 13:03:16
【问题描述】:

我想把css中的+号改成购物车。我已经在我的网站上安装了 Font Awesome,但是当我将 <i class="fa fa-cart-plus"></i> 行放入其中时,它不起作用。

它在 css 中看起来像这样,所以我希望内容中的 + 成为购物车。谁能帮帮我?

.woocommerce #content-container a.button.add_to_cart_button:before, .woocommerce-page #content-container a.button.add_to_cart_button:before, .woocommerce #content-container button.button.add_to_cart_button:before, .woocommerce-page #content-container button.button.add_to_cart_button:before, .woocommerce #content-containerinput.button.add_to_cart_button:before, .woocommerce-page #content-containerinput.button.add_to_cart_button:before, .woocommerce #content-container#respond input#submit.add_to_cart_button:before, .woocommerce-page #content-container#respond input#submit.add_to_cart_button:before, .woocommerce #content-container#content input.button.add_to_cart_button:before, .woocommerce-page #content-container#content input.button.add_to_cart_button:before, .woocommerce #content-container a.button.add_to_cart_button:before, .woocommerce-page #content-container a.button.add_to_cart_button:before, .woocommerce .products a.button.add_to_cart_button:before, .woocommerce-page .products a.button.add_to_cart_button:before, .woocommerce .products button.button.add_to_cart_button:before, .woocommerce-page .products button.button.add_to_cart_button:before, .woocommerce .products input.button.add_to_cart_button:before, .woocommerce-page .products input.button.add_to_cart_button:before, .woocommerce #respond.products input#submit.add_to_cart_button:before, .woocommerce-page #respond.products input#submit.add_to_cart_button:before, .woocommerce #content.products input.button.add_to_cart_button:before, .woocommerce-page #content.products input.button.add_to_cart_button:before, .woocommerce .products a.button.add_to_cart_button:before, .woocommerce-page .products a.button.add_to_cart_button:before {
color: #ffffff;
content: "+";
font-size: 20px;
left: 0px;
line-height: 10px;
margin-right: 15px;
position: relative;
top: 3px;

}

【问题讨论】:

    标签: css font-awesome


    【解决方案1】:

    您需要使用其 ASCII 代码添加图标。您可以在Font Awesome Cheat Sheet 中找出 ASCII。那里有所有图标及其 Unicode 表示。您想要的是fa-cart-plus。它的 ASCII 版本是分号前的四个十六进制数字,前导反斜杠:\f217

    一旦我们有了它,我们就可以在 CSS 中使用它,如下所示:

    HTML

    <p><span class="cart"></span></p>
    

    CSS

    .cart:before {
        font-family: FontAwesome;
        content: "\f217";
    }
    

    工作JSFiddle

    (显然您需要安装并包含 Font Awesome 库。)

    您的 CSS 应如下所示

    .woocommerce #content-container a.button.add_to_cart_button:before, .woocommerce-page #content-container a.button.add_to_cart_button:before, .woocommerce #content-container button.button.add_to_cart_button:before, .woocommerce-page #content-container button.button.add_to_cart_button:before, .woocommerce #content-containerinput.button.add_to_cart_button:before, .woocommerce-page #content-containerinput.button.add_to_cart_button:before, .woocommerce #content-container#respond input#submit.add_to_cart_button:before, .woocommerce-page #content-container#respond input#submit.add_to_cart_button:before, .woocommerce #content-container#content input.button.add_to_cart_button:before, .woocommerce-page #content-container#content input.button.add_to_cart_button:before, .woocommerce #content-container a.button.add_to_cart_button:before, .woocommerce-page #content-container a.button.add_to_cart_button:before, .woocommerce .products a.button.add_to_cart_button:before, .woocommerce-page .products a.button.add_to_cart_button:before, .woocommerce .products button.button.add_to_cart_button:before, .woocommerce-page .products button.button.add_to_cart_button:before, .woocommerce .products input.button.add_to_cart_button:before, .woocommerce-page .products input.button.add_to_cart_button:before, .woocommerce #respond.products input#submit.add_to_cart_button:before, .woocommerce-page #respond.products input#submit.add_to_cart_button:before, .woocommerce #content.products input.button.add_to_cart_button:before, .woocommerce-page #content.products input.button.add_to_cart_button:before, .woocommerce .products a.button.add_to_cart_button:before, .woocommerce-page .products a.button.add_to_cart_button:before {
        color: #ffffff;
        font-family: FontAwesome; /* Here */
        content: "\f217"; /* And here */
        font-size: 20px;
        left: 0px;
        line-height: 10px;
        margin-right: 15px;
        position: relative;
        top: 3px;
    }
    

    【讨论】:

    • 感谢您的回答!我无法让它工作。我需要把你写的行放在哪里?我需要把 HTML 行放在某个地方吗?
    • 看看我更新的答案。不需要 HTML 行。如果还是不行。确保您已正确“安装”FontAwesome 并包含 CSS 文件等。
    • 对不起我的愚蠢问题。但它仍然不起作用。我已经按照这个页面说的做了,但是我需要把 css 文件放在某个地方吗?
    • 如果没有看到您的实际项目就很难判断。可以给个链接吗?
    【解决方案2】:

    你试过&lt;i class="icon-shopping-cart"&gt;&lt;/i&gt; 吗? 见list of icons

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-02-29
      • 2017-11-05
      • 1970-01-01
      • 1970-01-01
      • 2018-09-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多