I want to use font awesome icons for a markup which is automatically generated and I cannot change that.
The following markup will display the ol
list. I want to replace the numbers with the icons.
<ol class="flex-control-nav">
<li><a class="flex-active">1</a></li>
<li><a class="">2</a></li>
<li><a class="">3</a></li>
<li><a class="">4</a></li>
<li><a class="">5</a></li>
</ol>
Here's what I'm trying:
.flex-control-nav a:before {
font-family: FontAwesome;
font-size: 30px;
display: inline-block;
content: '\f137';
}
Problem:
With the above code, I can display the icons in each list item, however the numbers are also there. I want to hide the numbers. I have tried using text-indent
, but that removes the icons also.
To replace the text with a logo image, use a negative text indent value (it has to be a pretty high value, like the one below) and insert the image using background: url(). Make sure you define the width and height as well, or the image won't render.
The text “Old Text” needs to be hidden first and a new text has to be positioned exactly where the old text was. To do so, we change the visibility of this text using CSS to hidden first. Then we add a new text at the exact same position, using the pseudo elements and corresponding explicit positioning.
The general practice is to display font awesome icons using their css class names & icon style class. If you are starting a new project then it's fine.
Just use
.flex-control-nav a
{
font-size:0;
}
Here's a Working Fiddle
OR:
.flex-control-nav a
{
visibility: hidden;
}
.flex-control-nav a:before
{
visibility: visible;
}
Here's a Working Fiddle
EDIT: I think I really misunderstood what you were asking for, but in case someone wanted to know how to get rid of the ol
numbers and replace them with the icons, here's a solution.
Basically, I got rid of the list numbers with list-style-type: none;
attached to the li
elements. Then I explicitly added a margin to the left of the ol
after getting rid of its default one. Finally, I took the icons out of the flow of the page and moved them left with a negative margin since that doesn't rely on bounding box positioning. As a side note, I made the line-height
of each of the list items the same as the font-size
of the icons so that the list items would be spaced apart appropriately.
CSS:
.flex-control-nav {
padding: 0;
margin: 0;
margin-left: 40px;
}
.flex-control-nav li {
line-height: 30px;
list-style-type: none;
}
.flex-control-nav li:before {
font-family: FontAwesome;
font-size: 30px;
position: absolute;
margin-left: -30px;
content: '\f137';
}
JSBin here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With