Start learning with our library of video tutorials taught by experts. Get started

CSS: Core Concepts

Basic text formatting: Solution


From:

CSS: Core Concepts

with James Williamson

Video: Basic text formatting: Solution

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.
Expand all | Collapse all
  1. 4m 57s
    1. Welcome
      55s
    2. Using the exercise files
      4m 2s
  2. 1h 7m
    1. Exploring default styling
      4m 56s
    2. CSS authoring tools
      2m 29s
    3. CSS syntax
      4m 45s
    4. Writing a selector
      4m 10s
    5. Setting properties
      8m 40s
    6. Common units of measurement
      7m 47s
    7. Inline styles
      5m 1s
    8. Embedded styles
      5m 19s
    9. Using external style sheets
      10m 34s
    10. Checking for browser support
      8m 48s
    11. Dealing with browser inconsistencies
      5m 30s
  3. 2h 15m
    1. Structuring HTML correctly
      2m 51s
    2. Element selectors
      4m 52s
    3. Class selectors
      6m 4s
    4. ID selectors
      3m 27s
    5. Using classes and IDs
      10m 7s
    6. Element-specific selectors
      4m 35s
    7. The universal selector
      5m 42s
    8. Grouping selectors
      4m 49s
    9. Descendent selectors
      7m 32s
    10. Child selectors
      5m 7s
    11. Adjacent selectors
      5m 30s
    12. Attribute selectors
      12m 43s
    13. Pseudo-class selectors
      3m 54s
    14. Dynamic pseudo-class selectors
      8m 29s
    15. Structural pseudo-class selectors
      6m 45s
    16. Nth-child selectors
      13m 10s
    17. Pseudo-element selectors
      12m 40s
    18. Targeting page content: Lab
      8m 56s
    19. Targeting page content: Solution
      7m 59s
  4. 42m 39s
    1. What happens when styles conflict?
      4m 0s
    2. Understanding the cascade
      5m 47s
    3. Using inheritance
      6m 11s
    4. Selector specificity
      6m 55s
    5. The !important declaration
      4m 5s
    6. Reducing conflicts through planning
      3m 33s
    7. Resolving conflicts: Lab
      6m 45s
    8. Resolving conflicts: Solution
      5m 23s
  5. 1h 47m
    1. Setting a font family
      7m 10s
    2. Using @font-face
      9m 18s
    3. Setting font size
      7m 35s
    4. Font style and font weight
      6m 52s
    5. Transforming text
      3m 58s
    6. Using text variants
      2m 49s
    7. Text decoration options
      4m 26s
    8. Setting text color
      3m 2s
    9. Writing font shorthand notation
      8m 49s
    10. Controlling text alignment
      6m 33s
    11. Letter and word spacing
      9m 11s
    12. Indenting text
      4m 30s
    13. Adjusting paragraph line height
      10m 30s
    14. Controlling the space between elements
      6m 41s
    15. Basic text formatting: Lab
      8m 45s
    16. Basic text formatting: Solution
      7m 14s
  6. 2h 1m
    1. Understanding the box model
      16m 53s
    2. Controlling element spacing
      14m 29s
    3. Controlling interior spacing
      10m 49s
    4. Margin and padding shorthand notation
      6m 27s
    5. Adding borders
      8m 57s
    6. Defining element size
      10m 7s
    7. Creating rounded corners
      6m 58s
    8. Background properties
      2m 51s
    9. Using background images
      5m 10s
    10. Controlling image positioning
      10m 25s
    11. Using multiple backgrounds
      7m 5s
    12. Background shorthand notation
      5m 25s
    13. Styling container elements: Lab
      7m 55s
    14. Styling container elements: Solution
      8m 17s
  7. 47m 51s
    1. Color keyword definitions
      5m 4s
    2. Understanding hexadecimal notation
      6m 5s
    3. Using RGB values
      4m 58s
    4. Using HSL values
      5m 17s
    5. Working with opacity
      2m 23s
    6. Using RGBa and HSLa
      3m 8s
    7. Styling drop shadows
      5m 38s
    8. CSS gradients
      6m 32s
    9. Working with color: Lab
      4m 26s
    10. Working with color: Solution
      4m 20s
  8. 1m 58s
    1. Additional resources
      1m 58s

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
CSS: Core Concepts
8h 49m Beginner Nov 22, 2011

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.

Topics include:
  • Exploring default styling
  • Writing a selector
  • Setting properties
  • Working with common units of measurement, including ems and pixels
  • Structuring HTML correctly
  • Understanding the cascade and inheritance
  • Setting a font family, font size, text color, and more
  • Understanding the box model
  • Styling container elements
  • Working with RGB vs. HSL values
  • Styling drop shadows
Subject:
Web
Software:
CSS
Author:
James Williamson

Basic text formatting: Solution

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.

Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS: Core Concepts.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

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.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked