【问题标题】:Using background image css for bootstrap icons将背景图像 css 用于引导图标
【发布时间】:2020-09-11 00:05:54
【问题描述】:

这是我的 HTML:

<a class="iconContainer" href="#">
  <span class="containerIcon chevron-right"/>
  Test
</a>

这是我的 CSS:

.chevron-right::before {
  display: inline-block;
  content: "";
  background-image: url("data:image/svg+xml,<svg width='1em' height='1em' viewBox='0 0 16 16' class='bi bi-chevron-right' fill='currentColor' xmlns='http://www.w3.org/2000/svg'><path fill-rule='evenodd' d='M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z'/></svg>");
  background-repeat: no-repeat;
  background-size: 10px 10px;
}

由于某种原因,图标未显示。这与此处的引导图标文档中显示的示例几乎相似: https://icons.getbootstrap.com/#usage

有人知道我做错了什么吗?我想我错过了一些非常明显的东西。这是它的 jsFiddle 链接。 https://jsfiddle.net/w5bvs7n6/8/

编辑:我想这与内容为空有关,但如果不是,我不知道它会如何工作。

【问题讨论】:

    标签: css twitter-bootstrap bootstrap-4 bootstrap-icons


    【解决方案1】:

    困难的方法是您必须使用转换器工具。能够在您的 CSS 中使用 SVG,例如 URL-encoder for SVG

    因此,您需要找到 SVG 文件并将其打开,将其内容复制到工具中并让魔法发生,然后您需要复制适合您的代码。

    完成此过程后,您将获得一个工作并准备好粘贴代码。您只需复制并使用它。

    .header__shape-quote::before {
        font-size: 4rem;
        position: absolute;
        top: -50px;
        left: -60px;
        background-image: url("data:image/svg+xml,%3Csvg width='1em' height='1em' viewBox='0 0 16 16' class='bi bi-chevron-right' fill='currentColor' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath fill-rule='evenodd' d='M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z'/%3E%3C/svg%3E");
        background-repeat: no-repeat;
        height: 40px;
        width: 40px;
        background-size: 40px 40px;
        content: "";
    }
    

    简单的方法就是按照路径调用它。

    .header__shape-quote::before {
        font-size: 4rem;
        position: absolute;
        top: -50px;
        left: -60px;
        /* calling the icon from the folder */
        background-image: url("../images/bootstrap-icons-1.0.0/chevron-right.svg");
        background-repeat: no-repeat;
        height: 40px;
        width: 40px;
        background-size: 40px 40px;
        content: "";
    }
    

    【讨论】:

      猜你喜欢
      • 2016-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-09-23
      • 2021-02-10
      • 2013-10-01
      • 1970-01-01
      相关资源
      最近更新 更多