Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add color inside an icon?

Tags:

css

I'm trying to color the background of an icon (from material-icons) but not beyond its outline (images illustration below).

As shown on this jsfiddle, I was only able to color the background but it does not fit the icon perfectly.

.material-icons {
  background:white;
}

Start :

enter image description here

What I try to get:

enter image description here

What I succeed to do :

enter image description here

I did not find a filled version of the icon. Ideally I don't want to use an other font just to answer that problem. Is it possible to do that in CSS or do I have to use a different version of the icon?

like image 219
Clemzd Avatar asked Feb 03 '17 16:02

Clemzd


1 Answers

Using absolute positioning, a 15px by 15px div, and border-radius 50% worked for me in JSFiddle.

enter image description here

HTML:

<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<div class="block">
  <div class="icon">
    <p class="iconfix">
      <i class="material-icons" style="color:green">check_circle</i>
    </p>
  </div>
</div>

CSS:

.block {
  width: 100px;
  height: 100px;
  background: grey;
}

.icon {
  background: #fff;
  width:15px;
  height:15px;
  border-radius: 50%;
  position: absolute;
  top: 1em;
  left: 1em;
}

.iconfix {
  position: absolute;
  top: -1.2em;
  left: -0.2em;
}
like image 83
Jeremy Avatar answered Sep 20 '22 18:09

Jeremy