Using Icon Fonts with the CSS content property and a simple Sass Mixin

Although I’m not the biggest fan of Icon Fonts and am having a closer look at svg at the moment, I used Icon Fonts a lot in the past. Mostly custom ones created by a Designer for me. At superReal we created a pretty nice Sass Mixin which helps using icons across your project in the same way and having an overview over all your icons in one place.

Every icon in an Icon Font is basically a character of the font. In our example writing a t with the Icon Font as the font-family will result in a twitter icon. But because icons are just graphics that would leave screen readers and search engines clueless because t doesn’t mean anything to them. So you should also provide a text version of every icon which can be indexed by search engines and used by screen readers. So to accomplish that I use pseudo elements with the content property to display the icons and hide the standard text with CSS.
The HTML looks like follows:

<a class="twitter-icon" href="http://twitter.com/_martinwolf">
    <span>Twitter</span>
</a>

With CSS we can than hide the span and only show the icon.
Our Mixin has three options. The first one is the $type and is the most important one and is mandatory because it defines which Icon is used from the if statement below. The second one is the pseudo element which by default is :before and the third is the display option which by default is block. We also define the font size (in the case of an icon font the size of the icon) and the line height in the Mixin for each icon individually within the if statement.
At last we hide the span element.

@mixin icon($type, $pseudo: before, $display: block) {
    &:#{$pseudo} {
        color: inherit;
        display: $display;
        font-family: 'Icons';
        -webkit-font-smoothing: antialiased;

        @if $type == burger {
            content: 'b';
            font-size: 70px;
            line-height: 37px;
        } @else if $type == facebook {
            content: 'f';
            font-size: 24px;
            line-height: 24px;
        } @else if $type == twitter {
            content: 't';
            font-size: 24px;
            line-height: 24px;
        } @else if $type == youtube {
            content: 'y';
            font-size: 24px;
            line-height: 24px;
        }
    }

    span {
        display: none;
    }
}

With this Mixin in place we can just call it and create our Twitter icon like that:

.twitter-icon {
    @include icon(twitter);
}

Be default the before pseudo element and display block is used. If we would want to change that we can do it like this:

.twitter-icon {
    @include icon(twitter, after, inline-block);
    margin-left: 10px;
}

This would result in the following CSS code:

.twitter-icon {
    margin-left: 10px;
}

.twitter-icon:after {
    color: inherit;
    display: inline-block;
    font-family: 'Icons';
    -webkit-font-smoothing: antialiased;
    content: 't';
    font-size: 24px;
    line-height: 24px;
}

.twitter-icon span {
    display: none;
}

If you want to use Entypo for example, a very popular Icon Font, you have to watch out for a little thing. Entypo and a lot of other Icon Fonts don’t give you a simple text for the content property, they instead give you a Unicode. But you can still use this Mixin you just have to escape the code it.

This is what you get from Entypo:

Screen-Shot-2014-01-04-at-14.19.42

And this is how you need to write your SCSS Mixin it to make it work:

content: '\1F50D';

I hope this helps you using Icon Fonts in your projects and makes your life a little bit easier.

#latr – Webseiten später anschauen

Ich speichere alle Artikel, die ich später lesen möchte in Instapaper. Das funktioniert hervorragend. Leider landen dazwischen immer wieder Webseiten, die ich aus irgendwelchen Gründen noch genauer betrachten möchte, Videos die ich noch sehen will oder Blogposts, die keine Artikel sind sondern viel mehr eine Ansammlung von Fotos.

Das ist blöd, wenn man diese Seiten dann mobil in sein Instapaper läd und wird erst richtig nervig, wenn man sich die Instapaperartikel auf den Kindle (Partnerlink) senden lässt. Deswegen muss da jetzt eine Lösung her.
Kurz mal bei Twitter nach Services gefragt, die das machen aber ich wurde entweder falsch verstanden oder mir wurde der klassische Bookmark empfohlen. Letzterer ist auch gar nicht so verkehrt und ich habe mit Delicious, einem Tag und ifttt.com eine Lösung gebastelt, die für mich funktioniert.
Da es vielleicht auch für den ein oder anderen interessant sein könnte, möchte ich euch kurz erklären, wie ich das ganze angehe.

Die ganze Vorgehensweise nennen ich unspektakulär latr. Ich habe mir ein Bookmark im Browser auf http://delicious.com/visuellegedanken/latr angelegt wo sich meine Liste mit Links befindet, die ich später noch anschauen will. Dort werden einfach alle Links angezeigt, die ich mit “latr” getagged habe. Die Bookmarks sind privat, deshalb seht ihr nichts, bzw im Moment nur einen Link. Ich kann also jetzt einfach über das normale Delicious Bookmark einen Link speichern, taggen und habe eine Liste mit Links. Wenn ich mir die Webseite angeschaut habe kann ich entweder einfach nur den Tag löschen oder einfach den Link aus meinem Delicious entfernen.

Soweit so gut. Oft finde ich aber Links durch Twitter und das dann auch noch auf dem iPhone. Ich brauchte dafür also eine Lösung.
ifttt.com ist großartig für genau solche Anwendungszwecke. Ich habe mir also ein “Rezept” angelegt, das immer wenn ich eine E-Mail mit dem Betreff #latr und einem Link als Text der E-Mail an trigger@ifttt.com schicke, bei Delicious einen privaten Bookmark mit dem Tag “latr” erstellt. (Wenn ich es richtig sehe, reicht es, wenn der Link das erste in der Mail ist, Text danach wird ignoriert.)

Das Rezept findet ihr hier und könnt es selbst nutzen: http://ifttt.com/recipes/4439

Das funktioniert hervorragend, ist mit der “Mail Link”-Funktion direkt aus Twitter for iPhone machbar und geht recht schnell. Ich mache das ja auch nicht zehn mal am Tag.
Wundert euch nicht, wenn es nicht sofort funktioniert. Dauerte bei mir auch etwas.

Ich hoffe ihr könnt etwas damit anfangen und euer Instapaper beherbergt jetzt auch nur noch Texte. Besseres Leben!