将字体真棒图标添加到css类

时间:2016-11-10 02:59:25

标签: html css css3 font-awesome

我有一个不同大小的小部件的仪表板。我需要创建一个在窗口小部件周围添加边框的单个类,并在现有内容之上的窗口小部件的右上角添加一个字体真棒图标。

我如何使用一个css类?

3 个答案:

答案 0 :(得分:4)

我不是百分之百理解你的需要,但我试着把一些东西贴近你的需要。

<强> 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>

答案 1 :(得分:3)

嗯,我明白这样的事情......

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;
}

我希望能帮到你。

答案 2 :(得分:0)

直接在按钮内或希望使用的任何地方使用真棒字体 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>
相关问题