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

CSS: Core Concepts

Targeting page content: Lab


From:

CSS: Core Concepts

with James Williamson

Video: Targeting page content: Lab

So now it's time to put what you've learned about selectors into practice by tackling our first lab. Now I've prepped a few pages of my fictitious desolve.org site that I want you to work on. Unlike the other exercises that we've completed so far, this is a true lab, so while I'm going to tell you what your goals are, I'm not going to tell you how to do it. In this lab, we're going to focus on properly targeting elements and writing efficient selectors. So the first thing I want you to do is go to the 02_18 folder and open up the contact.htm, galleries.htm, index.htm, philadelphia.htm, and inside the _css directory, the main.css.
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

Targeting page content: Lab

So now it's time to put what you've learned about selectors into practice by tackling our first lab. Now I've prepped a few pages of my fictitious desolve.org site that I want you to work on. Unlike the other exercises that we've completed so far, this is a true lab, so while I'm going to tell you what your goals are, I'm not going to tell you how to do it. In this lab, we're going to focus on properly targeting elements and writing efficient selectors. So the first thing I want you to do is go to the 02_18 folder and open up the contact.htm, galleries.htm, index.htm, philadelphia.htm, and inside the _css directory, the main.css.

Now we've been working with these really simple files throughout all of our exercises as we concentrate on the concepts. This is more of an applied lab, so this is more of a finished site. I just want to preview this for you so you can see kind of what you're going to be working with. So I'm just going to the index page and open this up in one of my browsers. So here is our site, and it's only partially styled. Some of the styles are finished; some of the styles are not. Your goals are going to be targeting specific elements within this site.

This is the index page, but we also have a page for contact. That's the contact page that we saw earlier. We have our galleries page where we have all these different galleries, and then we have one individual gallery page, and that would be Philadelphia. So the styles that you write are actually going to be targeting things on all four of these pages. If I go back into the structure of the code, each one of these pages has a link to the main.css file. So whereas in most of our exercises we've been adding the styles locally to the pages, in this one you're going to be adding your styles to the main.css file.

All the pages are structured in a very similar manner. Inside the body tag we have a header that has our pageHeader. Following that, we have a nav, which has the main navigation for the page. Notice the IDs of these sections as well. We have a section of our content. On the index page we have a banner that we don't have on other pages. Inside this content section, we typically have an article. The article's ID reflects the page that's on in the content that is inside of it.

And inside that we also have some individual sections, depending upon the pages that you're looking at. In this case, I have two sections with the class of news. Below our article, we have an aside, which serves as our sidebar. The aside is made up of a couple of elements. One of those is another nav. This is the nav with the ID of archives. Underneath that we have a couple of sections. These are our contest sections. The first one is this month's contest and the second one is the previous contest, but notice that they both have the class of contest applied to them.

And then finally we have our page footer that has that ID pageFooter. So that's how our HTML is organized. It's different depending upon which page you're on, but the overall structure is pretty much the same. If I go over to the main.css, this is a really large style sheet. It's actually an average-sized style sheet to be quite honest with you. At the very top of it I have a color guide to help us when we are choosing colors a little bit later on, and then the styles are organized by regions and by style type.

So global styles, the type of formatting that goes everywhere, comes first. After that, I have a section on basic layout styles. After that, I have a section on content region styles, and even those content region styles are organized by regions, so headers get its own region, the nav styles have their own region, that sort of thing. The most of the time you would go in and you would work within the appropriate section. Just to make this initial lab a little bit easier on you, I have actually grouped the selectors that we need down towards the bottom.

If you're in the CSS file with me, go ahead and scroll all the way down towards the bottom of it. We're going to go down to about line 618. On line 618 I have the Add lab selectors here. I'm not going to ask you to do any of the formatting. We haven't gone over enough properties yet for you to really tackle the formatting options. What I'm interested in, and what our focus was for this chapter was on writing selectors. Your goal is going to be targeting the appropriate elements on the page using the appropriate selector.

So I want to go over each one of these needs one by one and show you what they are going to style. The first one I want you to do is write a selector that targets every link element throughout the entire site. On our pages we have different links. We have them in different places. Some of them would be within the body copy, some of them are within the navigation. I want you to write a very generic selector that targets every single link all the way throughout the site. The second selector that I want you to write is write a selector that targets the copyright paragraph in the footer.

Now when you start getting into things like this, you're going to have to be really familiar with the structure of the page, and I know that one of the hardest things to do is to go into somebody else's page that they created and sort of sift through the way that they structured it, because it's almost always different than the way that you structured it. But what this does is it reinforces the fact that if you don't know the structure of the page you cannot write a selector for it. So you need to go back into the HTML, find those elements, such as the footer, and as this selector is asking us to do, write a selector that targets the copyright paragraph in the footer.

That would cause you to go back to that footer, look in the footer and find the copyright paragraph, and then figure out how to target this independently of anything else on the page. You'll need to do the same thing for the next one, which is asking you to write a selector that targets the dates inside the upcoming dates list on the index page. You can find that in the index page. And if I scroll up into my main section, I have these news, and here are the upcoming dates right there.

Sometimes it's helpful to preview that in the browser because it becomes very easy to see at that point, and it would be these dates. So that's what you're targeting there. Next, you want to write a selector that changes the background of every second list item in the unordered list that forms the archived gallery menu in the sidebar. So again, on each page you'll find the same structure where we have this aside and we have a navigation in there that has this list in it.

You're going to target it so that every second list item uses this background. Next, you'll need to write a selector that changes the color of the main navigation links. The main navigation links are these links right up here. So what you're going to need to do is write a selector that changes the color as users hover over those links. And again, it's going to target only the main navigation links, none of the other links on the page. We also need to write a selector that targets the search input text box in the footer, and make sure that it will only target the search input form element.

So again, you can go back down to the footer, you can take a look at the search input form element, and then try to figure out how to target only that particular element on the page. And then we're going to write a selector that will add the usage text you see here at the end of the photos gallery. So the photos gallery is in the Philadelphia page. If you scroll down, you'll find that we have a div with a class of photos. Inside that we have all of our images. You'll need to write a selector here that will add this content to the end of that photos gallery, so after it.

Now that you know what your goals are, go back, carefully study the structure of HTML, and try to write the most efficient selector possible. You should be able to accomplish every single one of these without modifying the HTML at all, so you shouldn't have to apply any extra classes, any IDs, or modify the code at all; you should be able to target them just the way the code is right now. One of the most challenging things about writing CSS is that there is almost always more than one way to accomplish what you're trying to do.

So don't worry too much about matching the exact selectors that I used to complete the lab; I want you to concentrate instead on writing a selector that correctly targets the elements on the page without affecting the styling of other elements. So as you test it, make sure the other elements aren't being affected. I also want you to focus on targeting these elements with the most simple selector possible. Now once you're finished, go ahead and check out the solutions movie that follows this one to compare your work to mine.

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