Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to use google material icons as class instead of <i> tag

According to the guideline in the Google Material website we have to use material icons in _i _ tag.

the question is how to add the icons as font-awesome. something like :

Class="material-icons face"

instead of

<i class="material-icons"> face </i>

like image 633
Fakhruddin Abdi Avatar asked May 17 '16 16:05

Fakhruddin Abdi


2 Answers

There's an easier way than the accepted answer. I got inspiration for this from the plugin css-toolip, which utilises the attr() css function (surprisingly has high browser adoption).

While attr() is supported for effectively all browsers for the content property... https://caniuse.com/#search=css%20attr

<span class="material-icons" data-icon="face"></span>

.material-icons:after {
    content: attr(data-icon);
}

This means that you don't have to add css for each icon that you want to use.

like image 168
Luke Madhanga Avatar answered Dec 11 '22 08:12

Luke Madhanga


Yes,you can add the material icons as classes using the after pseudo elements.check out the fiddle

 <span class="material-icons face"></span>

.face {
    position:relative;
    display:inline-block;
}

.face:after {
    content: "face";
}
like image 35
Vivekraj K R Avatar answered Dec 11 '22 09:12

Vivekraj K R