Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add a Google icon font to pseudo :before

Tags:

css

I'm using Google's material design icon fonts.

However I want to overlay one fone on top of another. The idea is to add a :before or :after element and style it something like this:

.material-icons:before
{
    position:absolute;
    content:"";
    color:@accent-color;
    font-size:2.4rem;
}

However, I'm not sure how to incorporate this:  into the content attribute - I'm tried a number of ways as well as using a converter on CSS tricks (which doesn't seem to work).

Any help appreciated.

like image 969
John Ohara Avatar asked Dec 10 '22 22:12

John Ohara


2 Answers

In CSS, to specify a character you would otherwise specify in HTML with the & escape, for example; ✏, you must use the \ escape, for example, content: "\9999".

.material-icons:before {
     position: absolute;
     content: "\E84E";
     color: #882288;
     font-size: 2.4rem;
}

To end an escaped character explicitly, use another \, for example content: "\E84E\ Hello World";

like image 87
Kana Ki Avatar answered Jan 03 '23 20:01

Kana Ki


You can achieve it by referencing the original Google Font css class which is:

.material-icons {
    font-family: 'Material Icons';
    font-weight: normal;
    font-style: normal;
    font-size: 24px;  /* Preferred icon size */
    display: inline-block;
    width: 1em;
    height: 1em;
    line-height: 1;
    text-transform: none;
    letter-spacing: normal;
    word-wrap: normal;
    white-space: nowrap;
    direction: ltr;
    /* Support for all WebKit browsers. */
    -webkit-font-smoothing: antialiased;
    /* Support for Safari and Chrome. */
    text-rendering: optimizeLegibility;
    /* Support for Firefox. */
    -moz-osx-font-smoothing: grayscale;
    /* Support for IE. */
    font-feature-settings: 'liga';
}

Using SASS you can extend it and set the content using a pseudo css element:

ul
    &:before {
        @extend .material-icons;
        content: 'label';
    }
}
like image 45
Kim T Avatar answered Jan 03 '23 20:01

Kim T