添加字体真棒图标到 css class

Adding a font awesome icon to a css class

我有一个包含不同大小的小部件的仪表板。我需要制作一个 class,在小部件周围添加边框,并在现有内容之上的小部件右上角添加一个很棒的字体图标。

我如何使用一个 css class?

嗯,我是这样理解的...

HTML

<div class="box">
  <div class="box-icon"></div>
</div>

CSS

.box {
   box-shadow: 0px 0px 10px #000;
   height: 5em;
   width: 5em;
}
.box-icon {
   position: relative;
}
.box-icon:before {
  content: "\f2da";
  display: inline-block;
  font-family: FontAwesome;
  position: absolute;
  right: -1.5em;
}

希望能帮到你

我不是 100% 理解您的需求,但我试图做出一些接近您的需求的东西。

HTML:

<span class="icon fa-id-card-o"></span>

CSS:

 .icon {
        display: inline-block;
        font: normal normal normal 14px/1 FontAwesome;
        font-size: inherit;
        text-rendering: auto;
        -webkit-font-smoothing: antialiased;
        -moz-osx-font-smoothing: grayscale;
        position: absolute;
        right: 0;
        color: red;
    }
    .icon:before {
        content: "\f2c3";
    }

.icon {
    display: inline-block;
    font: normal normal normal 14px/1 FontAwesome;
    font-size: inherit;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    position: absolute;
    right: 0;
    color: red;
}
.icon:before {
    content: "\f2c3";
}
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<span class="icon fa-id-card-o"></span>

另一个带有固定 div 的例子,就像小部件的

LIve view

HTML:

<div class="box">
  <span class="icon fa-id-card-o"></span>
</div>

CSS:

.icon {
    display: inline-block;
    font: normal normal normal 14px/1 FontAwesome;
    font-size: inherit;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: red;
    float: right;
}
.icon:before {
    content: "\f2c3";
}
.element.style {
}
.box {
    background: green;
    margin: 100px;
    display: block;
    width: 70%;
    height: 300px;
    }

.icon {
    display: inline-block;
    font: normal normal normal 14px/1 FontAwesome;
    font-size: inherit;
    text-rendering: auto;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    color: red;
    float: right;
}
.icon:before {
    content: "\f2c3";
}
.element.style {
}
.box {
    background: green;
    margin: 100px;
    display: block;
    width: 70%;
    height: 300px;
    }
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet"/>
<div class="box">
  <span class="icon fa-id-card-o"></span>
</div>

当直接在按钮内或任何你想要的地方使用 font awesome icons 时,你可以像下面那样使用

<i class="fab fa-rebel"></i>

按钮示例如下

 <button class="button">
    <i class="fab fa-rebel"></i>
 </button>

但是,当使用额外的 css 时,您可以使用 span。 下面的例子有一个额外的 css 'your-css'.

<button class="button">
     <span class="your-css fab fa-rebel"></span>
 </button>