Is there any way to embed HTML in the css content:
element when using a :before
pseudo-element?
I want to use a Font Awesome (or Glyphicon)
<ul class="icons-ul">
<li><i class="icon-play-sign"></i> <a>option</a></li>
<li><i class="icon-play-sign"></i> <a>option</a></li>
<li><i class="icon-play-sign"></i> <a>option</a></li>
<li><i class="icon-play-sign"></i> <a>option</a></li>
<li><i class="icon-play-sign"></i> <a>option</a></li>
</ul>
All the font awesome icons comes default with Bootstrap.
In the case of your list items there is a little CSS you can use to achieve the desired effect.
ul.icons li {
position: relative;
padding-left: -20px; // for example
}
ul.icons li i {
position: absolute;
left: 0;
}
I have tested this in Safari on OS X.
Re: using icon in :before
–
recent Font Awesome builds include the .fa-icon()
mixin for SASS and LESS. This will automatically include the font-family
as well as some rendering tweaks (e.g. -webkit-font-smoothing
). Thus you can do, e.g.:
// Add "?" icon to header.
h1:before {
.fa-icon();
content: "\f059";
}
@keithwyland answer is great. Here's a SCSS mixin:
@mixin font-awesome($content){
font-family: FontAwesome;
font-weight: normal;
font-style: normal;
display: inline-block;
text-decoration: inherit;
content: $content;
}
Usage:
@include font-awesome("\f054");
This is the easiest way to do what you are trying to do:
http://jsfiddle.net/ZEDHT/
<style>
ul {
list-style-type: none;
}
</style>
<ul class="icons">
<li><i class="fa fa-bomb"></i> Lists</li>
<li><i class="fa fa-bomb"></i> Buttons</li>
<li><i class="fa fa-bomb"></i> Button groups</li>
<li><i class="fa fa-bomb"></i> Navigation</li>
<li><i class="fa fa-bomb"></i> Prepended form inputs</li>
</ul>
The accepted answer (as of 2019 JULY 29) is only still valid if you have not started using the more recent SVG-with-JS approach of FontAwesome. In which case you need to follow the instructions on their CSS Pseudo-Elements HowTo. Basically there are three things to watch out for: