Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set icon font as background in CSS property

Tags:

All I want to do is replace a background image in CSS with an icon font, not icon image. I can't get it done. This is the CSS property:

.social-networks .twitter{background:url(../images/social/twitter.png);} 

This is the code in PHP:

<ul class="social-networks">     <?php if (my_option('twitter_link')): ?>         <li>             <a href="<?php echo my_option('twitter_link'); ?>"  class="twitter">twitter</a>         </li>     <?php endif; ?> 

The way I insert an incon font is <span class="icon">A</span>

like image 788
Dani Bălă Avatar asked Dec 13 '12 22:12

Dani Bălă


People also ask

How do I use font icons in CSS?

To use font awesome icons as CSS content code follow the below steps. Add a unique CSS class name to the icon element you want to use. Set the font-weight css property as 900 (For Solid), 400 (Regular or Brands), 300 (Light for pro icons). Set the content css property to the unicode value font awesome icon.

How do I use Font Awesome icons in external CSS?

In order to include Font Awesome , you need to include <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.1.1/css/all.css" integrity="sha384-O8whS3fhG2OnA5Kas0Y9l3cfpmYjapjI0E4theH4iuMD+pLhbf6JI0jIMfYcK3yZ" crossorigin="anonymous"> on your html file then use it to css .

Can icon fonts be styled?

Icon fonts are just fonts. However, instead of containing letters or numbers, they contain symbols and glyphs. You can style them with CSS in the same way you style regular text which has made them a popular choice on the web.


2 Answers

You could try something like this: FIDDLE

Let's say you have your DIV:

<div class="test"></div> 

you create your css style like this:

.test {     width: 100px;     height: 100px;     border: 2px solid lightblue; }  .test:before {     content: "H";     width: 100%;     height: 100%;     font-size: 5.0em;     text-align: center;     display: block;     line-height: 100px; }​ 

in the property content you choose your "letter" and then you can change the font-size, font-weight, color, etc...

like image 178
Dim13i Avatar answered Nov 22 '22 07:11

Dim13i


There is a content property in css:

.icon-rocket:after {    content: "{Symbol for rocket}"; } 

http://www.w3schools.com/cssref/pr_gen_content.asp

like image 41
E_p Avatar answered Nov 22 '22 08:11

E_p