Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adding a font awesome icon to a css class

I have a dashboard with different sized widgets. I need to make a single class that adds a border around the widget, and also adds a font awesome icon to the top right of the widget on top of the existing content.

How i do this with one css class?

like image 981
Michael Christopher Martire Avatar asked Nov 10 '16 02:11

Michael Christopher Martire


People also ask

How do you add icons before CSS?

The CSS3 pseudo-element ::before will place the icon before the link text. In this example, the ID selector for the menu's home link is #menu-link-1 which you can see by right-clicking the link and choosing Inspect in the browser menu. You can also use the ::after pseudo-element to place an icon after the link text.

How do I use Font Awesome icon in pseudo element?

Enable Pseudo-elements Using CSS Pseudo-elements to render icons is disabled by default when using our SVG + JS Framework. You'll need to add the <script data-search-pseudo-elements ... > attribute to the <script> element that calls Font Awesome.


1 Answers

I am not 100% understand your need but i was try to make something make close of your need.

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>

ANOTHER EXAMPLE with a fixed div like a widget's

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>
like image 195
MD Ashik Avatar answered Sep 18 '22 01:09

MD Ashik