Start learning with our library of video tutorials taught by experts. Get started
Viewers: in countries Watching now:
Icon fonts are a fast, effective way to feature scalable vector artwork on websites. James Williamson shows you how to properly deploy icon fonts on your own site in this short course. Learn how to find an icon font that's right for you and style it so it appears exactly the way you want. Then learn about deployment options that will make your icons accessible and display consistently across multiple browsers and devices. James also introduces advanced styling options such as animated and multicolored glyphs.
Want to create your own icon fonts? Check out James' companion course, Creating Icon Fonts for the Web.
We're almost finished with our multicolored icons. In our last exercise, we structured the HTML for them. So in this exercise, we'll concentrate on the styles. Now I'm going to go into my code editor. And I have the multicolor.htm, open from the 04_06 directory. Now, we're picking up right where we left off. So, if you have the previous file open. And you just want to keep working on that, that's fine. Just as a refresher, to let you guys know kind of, what kind of structure we're dealing with here.
We've got two spans, one is nested inside of the other. The outside span has two classes applied to it. One is multi. To let us know that it is a multicolored icon. And the other one identifies which icon it is. In the case of the one that we're going to be styling, that would be maps. Alright, I'm going to open up my CSS file, which is the base.css. And I'm going to scroll all the way down towards the bottom. Where I'll find my icon font styles. Now, as I get towards the bottom, I've got some commented styles down here for a multi-color colors.
What does that mean? Well for the multi-color icon. These are the colors that we're going to be using. We'll turn our attention to those in just a moment. What I want to do right now, is make sure that our multicolored icons are lining up one on top of the other. So the first thing we're going to do is we're going to write a selector that targets any of the multicolored spans. So we're just going to say span.multi. Open up a couple of curly braces. Now let's talk about the properties that we need for this. The first thing that I'm going to do, is I'm going to set position to relative. Now the reason for that is, in order to have these two stack one on top of each other.
We have to use some pretty fancy positioning tricks. In this case I'm going to use a very old trick. Which is the parent element will get a position, a style of relative. While the nested one will get a position of absolute. Absolute positioning will take an element out of normal document flow. And then position it relative to the nearest positioned parent. I know that sounds really weird. But if you don't have a nearest positioned parent, it's positioned relative to the window itself. So, by giving the parent a position of relative.
We're making sure that the absolutely positioned interior icon lines up with this one. Okay? I know, if you've done that before I know that doesn't make sense. But some of you guys I'm sure have used this trick once or twice before. But trust me when I tell you it, it's going to work. Alright I'm going to do a display property of block. That's going to make sure that these guys are displaying in their own individual space, within the normal document flow. And that I can use box model properties on it. The next thing I'm going to do is give it a width of 64 pixels.
The width value isn't required to display our icons on top of each other. This is more to make sure that it fits within the parent box and is centered. Because the very next property I'm going to apply are my margins. And for margins, I'm going to do 0 for top and bottom. And auto for left and right. Which is going to center it horizontally. Alright, I'm going to go ahead and save that. And now I've got to move on to the interior span. And this is the one that we have to position right on top of this parent one. So for that one, I'm going to do the same selector again.
Span.multi space span. So we're saying hey, let's target any span inside of a span, with a class of multi. Alright, so we're getting pretty specific here. Inside of that, I'm going to go ahead and give it a positioning attribute as well. This one is going to be absolute. And then I'm going to give it a top value of 0, and a left value of 0. And what that's going to do, is it's going to take the interior span, which is the interior icon. And it's going to line it up at the top left hand corner at 0, 0 of its parent.
Alright, I'm going to save this. Preview this in a browser. And if I scroll down. Excellent. So all of my multi-colored icons are overlaying one another. The problem obviously, is they're still multi, they're still single color. So now what we're going to do, is we're going to go back into our styles. And we're going to assign some color. Okay, so I'm back in my styles. And I'm going to scroll down a little bit. And I'm going to un-comment, not the actual comment itself, I need that. I'm going to un-comment out these individual classes down here. Now, these are targeting all of the other icons.
So we need to write our color assignments for our map. And I'm just going to go up to the very top of this, because it's the first element. So I think it probably should be up top. Alright, so I'm going to use the class that we use to identify, which is maps. Now for this one, I'm going to give this a maps a color of #7D7893. It's kind of an off, I don't know, almost pewter blue. I think, is what this is.
And now remember, because the outer parent is maps. Now both of these, the interior and the stacked icon. Both now have this color. So we have to now target the interior span. So I'm going to write a selector that's .maps space span. And I'm going to give it a color as well. And the color for the interior one's going to be sort of a, sort of an off-red, I guess, off-pink. 7B. 3, 1, 2, 3. And then the semicolon.
And feel free to experiment with the colors. And make them any way that you want. You can probably do a better job than me at assigning colors. I'm going to save this, go out to my browser. And as I see, I've got nice, multicolored icons. Well there you have it. Of course, you know, how you actually structure and style your multicolored icons are going to be in large part determined by how they are created. Some, I've actually seen a couple of icon font sets that use what they call, zero width characters. And to do that you just put two spans side by side, display them in line.
And they overlap each other. So there are multiple ways to do this. I, I want you to notice however, that we found a way to do it that fit squarely within the deployment strategy that we had planned for our icon fonts. And that just requires that you understand a lot about the icon font that you're using, and how it's constructed.
There are currently no FAQs about Deploying Icon Fonts for the Web.
Access exercise files from a button right under the course name.
Search within course videos and transcripts, and jump right to the results.
Remove icons showing you already watched videos if you want to start over.
Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.