Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace text with icon with css

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.

like image 981
user2738640 Avatar asked Oct 07 '13 06:10

user2738640


People also ask

How do I replace text with an image in CSS?

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.

How do you replace text in CSS?

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.

Can we use an awesome font icon with CSS?

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.


2 Answers

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

like image 125
avrahamcool Avatar answered Nov 15 '22 20:11

avrahamcool


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.

like image 20
jsea Avatar answered Nov 15 '22 21:11

jsea