Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Font Awesome Background color

Tags:

font-awesome

When using the brilliant Font Awesome, how can I make the icons not transparent - for instance if I want to use http://fortawesome.github.io/Font-Awesome/icon/chevron-circle-up/ but not have the "up arrow" within the black circle be transparent but solid color (white)?

Thanks!

like image 796
John Anderson Avatar asked Oct 22 '14 20:10

John Anderson


People also ask

How do I add background color to Font Awesome icons?

You can simply set a single "color" property to set the color of the character/icon to be what you want. If the background circle offsets the icon, you can use line-height to fix it.

How do you change the color of a Font Awesome?

Changing the color and size of the icons To change the color of the icons, simply add or change the “color” property in the CSS. So to change the color of the icons to red in the above example, add “color:red” to the .

How do I fill a color with icon?

To change the color of an icon, select the icon you'd like to edit. The Format tab will appear. Then click Graphics Fill and select a color from the drop-down menu. To add an outline to your icon, click Shape Outline and select a color from the drop-down menu.

Is Font Awesome no longer free?

Font Awesome Free is free, open source, and GPL friendly. You can use it for commercial projects, open source projects, or really almost whatever you want.


2 Answers

UPDATE: As xavier pointed out below, font-awesome has Stacked Icons which will let you put a circle behind an icon without using a hack. Essentially, you stack whichever icon you want on top of their fa-circle icon. You can then style the circle independently from the icon and change it to whatever color you'd like.

Here's an example based off of code from their site:

.fa-circle {   color: black; }
<link href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css" rel="stylesheet"/>  <span class="fa-stack" style="vertical-align: top;">   <i class="fas fa-circle fa-stack-2x"></i>   <i class="fas fa-chevron-up fa-stack-1x fa-inverse"></i> </span>

ORIGINAL ANSWER: Unfortunately, the whole icon is considered a single "character" on the page and as such, you don't have that granular of control over it. You can simply set a single "color" property to set the color of the character/icon to be what you want.

Now, it is possible for a creative hack though. Since the middle of the character is transparent, you can set a colored background behind the character to make it appear that the middle is a different color by doing something like this:

    <i class="fa fa-chevron-circle-up"></i> 

then in your CSS:

.fa-chevron-circle-up {   background: yellow;   border-radius: 50%;   height: 1em;   width: 1em; } 

If the background circle offsets the icon, you can use line-height to fix it.

like image 98
Kyle Goode Avatar answered Sep 28 '22 21:09

Kyle Goode


you can use fa-stack with the fa-circle icon under the other to have better control on the pixel just at the border:

<span class="fa-stack">     <i class="fa fa-circle fa-stack-1x icon-a"></i>     <i class="fa fa-times-circle fa-stack-1x icon-b"></i> </span> 

with:

.icon-a {     color: #FFF;     font-size: 0.9em; } .icon-b {     color: #000; } 
like image 40
xavier bs Avatar answered Sep 28 '22 21:09

xavier bs