Icon Fonts & Pseudo Elements

Lesson Number 19, October 8, 2014

Homework

Lesson

  1. Questions about type
  2. Icon fonts
  3. Pseudo-classes / Hovering things
  4. In-Class Activity

Icon Fonts

Why are Icon Fonts Awesome?

Icons are great for providing a little bit of extra visual meaning to your content. They can provide visual interest, and allow for easier communication with your audience.

The overuse of icons should be avoided, and you should take care that your icons are communicating the correct meaning to the audience. Text labels should accompany icons when possible.

Here are four articles about icon usability

How to Use Icons

Traditionally, images have been used as icons on the web. If you visit sites like IconFinder or simply google "web icons" you will find lots of different icons that you can use in your designs. These types of icons would be included on your site exactly like you would include an image.

<a href="http://www.facebook.com">
  <img src="img/fbicon.png" alt="Facebook Icon" />
</a>

Facebook Icon

Alternate - using image fonts

Using image as icons has lots of pros (you can get really custom with your icons, do cool things), but also some drawbacks. What if you want a larger icon? You would have to find some way to enlarge your image. What if you want to change the color? You would have to recreate your image.

With modern browsers we have the option of using icon fonts. Icon fonts allow you to highly customize your icons, changing size and color - they act a lot like text on your website!

Using Icon Fonts

I like using FontAwesome for my icon fonts. I find that most of the icons I want to use are included, and it's really easy to add to projects. You'll see that we actually use these in the Nest, and on some of SJU's other websites.

FontAwesome

You can use FontAwesome without having to download anything. Simply follow the instructions on FontAwesome's site.

Custom Icon Fonts

Using a library like FontAwesome is awesome, because it's all built right for you. If you are only using a few icons, or you want to create your own icon set, you may wish to use a service like IcoMoon. A great tutorial that leads you through this process (including creating your own font, downloading the files, and including them in your website) is available on Go Make Things.

CSS Pseudo Classes

So far we have been using CSS selectors like the following:

ul { .. } /* Type or Element Selector */

.myclass { .. } /* Class Selector */

#mainheader { .. } /* ID Selector */

We've also learned that we can combine selectors, like so:

header.main { .. } /* This will target the element header with the class of main, so <header class="main"> */

.myclass a { .. } 

/* This will target all the links that are descendants of .myclass  
    <div class="myclass">
      <p>This text will be <a href="#">styled</a></p>
    </div>
*/

Another way we can use CSS is to talk about specifics of an element. So, you may have seen something like this before

a:link, a:visited {
    color: blue;
}

The :link and :visited that are stuck to the selector (in this case, a) are called pseudo classes. Pseudo classes are used to be more specific about how you want your CSS to appy, and when.

A great use-case for this is to change link styling when you hover over the link.

For example, we may have CSS that's as follows:

.example a {
    font-size: 2em;
    color:green;
    text-decoration: none;
}

And the result is:

This is my link

But let's say that when the user hovers over it, we want it to change in some way. For example, we may want to underline, or change the color. Let's do both.

We do this by using the :hover pseudo class. When we stick :hover right onto the selector, we're saying "Hey, apply this CSS when I'm hovering over this thing!"

.example a:hover {
    color: blue;
    text-decoration: underline;
}

And the result is:

This is my link

  1. Open your project portfolio in Brackets.
  2. Open index.html.
  3. At the end of the file, BEFORE the </body>, create a new element - footer. Add a class to your footer, called 'site-footer'

    <footer class="site-footer">
    </footer>
    

  4. Create a list inside your footer. Add three list items. Make them GitHub and Email.

    <footer class="site-footer">
    <ul>
    <li>GitHub</li>
    <li>Email</li>
    </ul>
    </footer>
    

  5. At the TOP of your document, before your linked CSS file but after your </title> add the following line. I got this from FontAwesome's Getting Started page. We are using their CDN so that we don't have to download anything separate.

    <link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
    

  6. Go back down to the footer. Add icons. You can use <span> or <i> as the element to add your icons. In this example we will use span.

    <footer class="site-footer">
    <ul>
    <li><span class="fa fa-github"></span> GitHub</li>
    <li><span class="fa fa-envelope"></span> Email</li>
    </ul>
    </footer>
    

  7. LivePreview! Do you see the icons in your footer?

  8. Now, let's link these! After the <li> open tag, start an <a>. The href should go to your GitHub page. Don't forget to close your <a>

    <li>
    <a href="http://github.com/com372-14">
    <span class="fa fa-github"></span> GitHub
    </a>
    </li>
    

  9. Let's link your email. Use mailto:MYEMAIL@EMAIL.COM as the value for href.

    <li>
    <a href="mailto:MYEMAIL@EMAIL.COM">
    <span class="fa fa-envelope"></span> Email
    </a>
    </li>
    

  10. Save your changes. Open your style.css

  11. Create a new css rule to target the links in your footer. Pick a font-size and a color!

    .site-footer a{
    font-size: 2em;
    color: green;
    }
    

  12. Create a second css rule to target the links in your footer when you hover them. Make them a different color!

    .site-footer a:hover{
    color: purple;
    }
    

  13. Save your work and commit to GitHub.

Finished and class isn't over?

  1. Add another footer link. Link to a social media profile. Find the icon on FontAwesome's icon page
  2. What happens if you try to add :hover to another element? Try to change the color of the text inside your color squares when you hover on them.

    Hover below to view the solution.

    .color1{
    color: white;
    }
    .color1:hover{
    color: yellow;
    }
    

  3. Try to figure out how I just did THAT (hovering to see the solution). Don't cheat by looking at my code, since I had to use a bit of a hack to override the default styling on our course website.

Homework

  1. Read Chapter 13 in your web design book.
  2. Read the articles from the lesson
  3. Don't forget to submit your CodeCademy that was due today.