Viewers: in countries Watching now:
In this hands-on course, James Williamson demonstrates the concepts that form the foundation of Cascading Style Sheets (CSS), including styling text, adding margins and padding, and controlling how images display. The course also explores the tools needed to work with CSS, the differences between embedded and external styles, how to use selectors to target elements, and what to do when styles conflict.
So, how did you do with our text formatting lab? When I last left you, I left you with a pretty big pile of stuff to do. So hopefully, you got through it okay, but, hey, if got stuck, feel free to open up the finished_files, compare your styles to the one in the finished_files directory and you've finished them, just come along with me in this movie and you can compare your finished styles to mine as we go through our tasks sort of one by one, I'll show you how I've solved the formatting issues as well. The first thing I want to do is just preview this page in a browser so you can see kind of the finished formatting.
So now our heading looks great, it looks a lot better than it did before, our font styling is looking really good, we've got the font that we were looking for in terms of our Cantarell font. The Twitter link right here is vertically centered with our bird. So everything is looking pretty much the way that we wanted it to. Cool, excellent. So let's go take a look at how we solved some of those issues. So I am going to back in my main. css and I am just going to go through these guys one at a time. Now the fonts was pretty simple to do, it's just simply cut and paste, copy and paste.
So that was probably pretty easy one for everyone. But remember, we had to go into our body selector, and let me find that real quick. So in order to do kind of what we wanted to there, I went ahead and used the font shorthand notation and I passed a font size of 100%, because remember, we asked to make the size of our text equal to whatever the default size of the text of the browser would be, and then we chose the Cantarell, Arial, sans-serif font stack. Now you may have noticed that at the bottom of this, I also chose the font-weight of normal and font-style of normal.
It's interesting, this is kind of redundant, I also do that right here without even really having to break a sweat. Remember, if you use the shorthand notation, but you don't pass those values, normal gets passed for those values. So why did I do it here? Well, that's my way of just sort of advertising to anybody else that comes along that hey, I'm going ahead and resetting font-weight and font-style to normal, everybody is going to inherit that, and then if you want it to be different, if you want it to be italic, if you want it to be bold, you've got to go ahead and set that automatically.
I also went ahead and set the color to that ASH color that we wanted to do and I again, I used those values from the color guide that we have above that. For line-height, notice I mentioned I wanted every single element to be 1.5 times their own font size. That's why we used a multiple here instead of 1.5ems. If we'd used ems there instead of a multiple, remember it would have calculated the value and then the calculated value would've got passed down, not the multiple. So it's a very, very important thing to remember. Now, if I go down a little bit further, I can see where I asked you to reset strong and em.
Those were pretty easy to do. We just did a strong selector and an em selector. We reset strong's font-weight to bold and we reset ems font-style to italic, so again, fairly simple. And for our default link styles, I am just going to scroll up a little bit here and I just used very simple selectors. Remember, I want this just to be the most basic link formatting possible. So what we did here is we did a text decoration of none, that's going to strip out all of the text decoration, the underline. I set the color to that Burnt Orange that we wanted it to be and then for hover, I set the color to that Blue Pewter color that we wanted, again using those RGB values from the color guide up top, and if you used the hexadecimal values, nothing wrong with that, it works just perfectly fine.
But remember, these selectors, I just use the most simple selectors that I possibly could, just the a and the a:hover. All right, now I'm going to scroll down a little bit and as I scroll through here, I wanted to point something out. You know one of the things that I asked you to do was to go ahead and use the Cantarell stack on the body. But you may have noticed that some of the headings didn't use Cantarell. I actually do have another stack going on and let me scroll down to try to find one of those. Here we go. You can see that the other stack that we are using is using the web font, Cardo, so there is another web font being used here as well and it's a serif font so we can have the fall back fonts being Georgia and Times there as well.
Okay, I want to go back up to about Line 184 and what we are going to talk about here are those header h1s and header h2s. How we did that. Now I mentioned I wanted the font-size to be 3.2 times the parent font-size and to do that we use ems. So hopefully, you caught the hint there and did 3.2ems. We are changing the font-weight to bold. We used the text-transform property to transform that particular text to all uppercase. We set the line-height to that explicit 165 pixels, so we used that as well and then the rest of the formatting was kind of already there.
For the heading 2, we set the font-style to italic, we set font-weight to normal. We did the same thing with ems, so 1. 4 ems, and then we set the line-height there to 165 pixels as well. We used text-transform to change that to all lower case and we changed the letter-spacing to .1ems which gives a slightly bigger spacing. Just to give you a visual idea of what we were doing there, this is the result of that. So this is our DESOLVE in all upper case, this is all lowercase and notice now the letter spacing is there, it's kind of pushing that apart a little bit, and because they both have a line-height of 165 pixels, they center each other vertically, which is a really nice little technique.
All right, now if I go down to about Line 224, I can find that #mainNav a selector that I wanted to talk about. I am doing a text transform on that to change this display to uppercase. I change the color to what we were wanting and I change the font-size to 1.2 ems, so that's 1.2ems, again 1.2 times the parent element and I changed the text-align to center. A little bit further down, I could find that mainNav a em selector and again, what I am doing there is I am doing a text- transform to lowercase and the font-size, it's already set there I believe at .8ems.
So what does that do for us? Well, again, it does this. So we have all caps here, we have text-align to center, so these two lines of text are lining up on each other and below that we have our italicized all lowercase text. Now finally, if we get all the way down to about line 674, we'll find that page footer a. Now that's targeting this element, right there. Here I give you a very cryptic clue. I said I wanted that link to be vertically aligned with the background image and I said look at the height of the element and there's your hint.
So you can see here we also have a line-height of 100px. So with a line height matching the height of the element itself, it goes ahead and just vertically centers that text directly in that element. So there's your 100px and that vertically centers it with that element. Now remember, if your styles don't exactly match mine, it's not a problem if they still work. You know there is always more than one way to accomplish something in CSS. So if you've come up with something that I didn't, awesome way, to go. However, if our styles are different, I do want you to take the time to examine those rules and think about which one is more efficient and easier to update and I can give you no promises that it's mine, it might be yours.
As always, not just having the right selector but having the most efficient selector should be a very important goal for your site.
There are currently no FAQs about CSS: Core Concepts.
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.
Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.