Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add google material design icon in css pseudo :after content

Tags:

I just wanted do add some of googles material design icons to the content of a link on hover:

a:hover::after {     content: "<i class="material-icons">link</i>" } 

but it does not work, please see my fiddle.

like image 675
Sebastian S. Avatar asked Nov 10 '15 12:11

Sebastian S.


People also ask

How do I use Google material icon in CSS?

First step is to add the link of material-icons font library in the <head> section of your HTML file. Here is how you do it. Once you have added the link of the material-icons library, the next step is to add the class “material-icons” in the <i> or <span> tag of the <body> section and also add the name of the icon.

How do I add font awesome icon to pseudo element?

You just have to add the following CSS to your after or before element: font: normal normal normal 14px/1 FontAwesome; content: '\f042'; Here the content is the icon you want to add. Just copy the Unicode of the icon from the FA website and paste it in the content with a \ prefix.

How do I use material icon code point?

See also Google's list: codepoints. To use a Material Icon as CSS pseudo content (:before, :after): xe23c becomes content:"\e23C" . You can use ligatures in pseudo elements, but this will not be supported in IE9. For more stuff, visit me at btn.


2 Answers

Change your CSS to this:

a:hover::after {   font-family: 'Material Icons';   content: "link";   -webkit-font-feature-settings: 'liga'; } 

So you can change the content: "[whatever icon here]";

FIDDLE

Also the fiddle didn't correctly load the icon font so put I placed the link in the html.

like image 52
C.Schubert Avatar answered Sep 18 '22 01:09

C.Schubert


C.Schubert was almost there with their answer but if you also want to have IE10+ support you need to add font-feature-settings: 'liga' 1; So the finished styling will look like this...

a:hover::after {   font-family: 'Material Icons';   content: "link";   -webkit-font-feature-settings: 'liga' 1;   -moz-font-feature-settings: 'liga' 1;   font-feature-settings: 'liga' 1; } 

And like C.Schubert said change the content: "[whatever icon here]"; to your desired icon.

like image 37
Ed Fryed Avatar answered Sep 21 '22 01:09

Ed Fryed