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

CSS3 First Look

First, last, and only structural selectors


From:

CSS3 First Look

with James Williamson

Video: First, last, and only structural selectors

In this movie, we are going to take a closer look at using our remaining structural pseudo class selectors. First, last, and only type structural selectors allow you to introspect the children of a parent element and then target child element based on their position, amount, and status within the parent element. So I have the 02_10.htm file opened. Now I just want to point out, a very simple page structure here. I am going to scroll down a little bit and we can see that we have three div tags. Inside those div tags, we have a mixture of heading 1s, paragraphs, and heading 2s.
Expand all | Collapse all
  1. 3m 5s
    1. Welcome
      1m 20s
    2. Using the exercise files
      1m 45s
  2. 31m 30s
    1. What is CSS3?
      5m 26s
    2. The current status of CSS3
      3m 35s
    3. An overview of CSS3 capabilities
      2m 24s
    4. Can you use CSS3 now?
      5m 31s
    5. Detecting support for CSS3
      9m 0s
    6. Understanding vendor prefixes
      5m 34s
  3. 1h 9m
    1. An overview of child and sibling selectors
      3m 11s
    2. Using child and sibling selectors
      7m 17s
    3. An overview of attribute selectors
      3m 19s
    4. Using attribute selectors
      8m 32s
    5. Pseudo-class UI selectors
      5m 56s
    6. Negation pseudo-class selectors
      6m 48s
    7. Target pseudo-class selectors
      5m 39s
    8. Structural selectors
      3m 58s
    9. Nth-child selector syntax
      10m 0s
    10. First, last, and only structural selectors
      5m 39s
    11. Using structural selectors to write more efficient code
      8m 52s
  4. 45m 28s
    1. Color formats in CSS3
      7m 9s
    2. Transparency in CSS3
      9m 10s
    3. CSS3 gradients
      4m 11s
    4. Creating linear gradients
      13m 57s
    5. Creating radial gradients
      11m 1s
  5. 49m 8s
    1. Working with web fonts
      6m 38s
    2. @font-face syntax
      4m 52s
    3. Downloading sample fonts
      6m 5s
    4. Writing @font-face declarations
      7m 57s
    5. Using web fonts
      6m 42s
    6. Using text shadows
      7m 14s
    7. Creating multi-column text
      9m 40s
  6. 50m 55s
    1. An overview of the flexible box model
      4m 42s
    2. Controlling box orientation
      5m 2s
    3. Setting element flexibility
      12m 59s
    4. Distributing boxes
      7m 54s
    5. Controlling box alignment
      12m 38s
    6. Working with box-sizing
      7m 40s
  7. 1h 5m
    1. Using border-radius
      6m 20s
    2. Creating custom rounded corners
      10m 21s
    3. Understanding border images
      5m 15s
    4. Using border images
      8m 52s
    5. Creating box shadows
      8m 58s
    6. CSS3 backgrounds
      4m 55s
    7. Controlling background size
      8m 46s
    8. Creating multiple background images
      6m 4s
    9. Using background-origin
      3m 18s
    10. Clipping background content
      3m 2s
  8. 40m 8s
    1. An overview of CSS3 2D transforms
      4m 26s
    2. Using 2D transforms
      8m 16s
    3. Setting transform origins
      5m 24s
    4. An overview of CSS3 transitions
      5m 0s
    5. Animating CSS properties
      6m 12s
    6. Using easing in animations
      5m 41s
    7. An overview of 3D transforms
      5m 9s
  9. 37m 56s
    1. Understanding media queries
      6m 18s
    2. Strategies for targeting multiple devices
      6m 4s
    3. Writing styles for target screen sizes
      12m 11s
    4. Deploying styles through media queries
      3m 55s
    5. Basing media queries on page orientation
      2m 24s
    6. Targeting media queries for iOS devices
      7m 4s
  10. 1m 6s
    1. Goodbye
      1m 6s

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...
CSS3 First Look
6h 34m Appropriate for all Nov 29, 2010

Viewers: in countries Watching now:

In CSS3 First Look, staff author James Williamson provides an in-depth introduction to the newest CSS standard, detailing its modular format, history, and current level of browser support, while also demonstrating its capabilities and applications. The course includes tutorials on using new selectors, modifying typography and color, working with the box model, and understanding media queries. Exercise files accompany the course.

Topics include:
  • Understanding the history of CSS3
  • Working with the new selectors
  • Adding transparency and gradients
  • Specifying web fonts with @font-face
  • Understanding the advances to page layout
  • Looking at CSS3 box model capabilities
  • Using 2D and 3D transforms
  • Understanding media queries
Subject:
Web
Software:
CSS
Author:
James Williamson

First, last, and only structural selectors

In this movie, we are going to take a closer look at using our remaining structural pseudo class selectors. First, last, and only type structural selectors allow you to introspect the children of a parent element and then target child element based on their position, amount, and status within the parent element. So I have the 02_10.htm file opened. Now I just want to point out, a very simple page structure here. I am going to scroll down a little bit and we can see that we have three div tags. Inside those div tags, we have a mixture of heading 1s, paragraphs, and heading 2s.

If I preview this in a browser, you can see there's some very basic styling on it. What we are doing is, we are going to use those first, last, and only selectors to target specific elements and then just change their color to red so that we know that we are successfully targeting those elements. So I am going to close out of this and scroll up and I can find in the head of my document a section where I'm going to be writing some of these selectors. Now the way that we are going to do this is we are just going to write the selector and then comment it out and then write another one to follow behind it.

So you can do this or you can just change the selectors if you would like. It's really kind of whatever you want to do. That's fine by me. The first thing I want to do is I want to find out exactly what this first child selector does. So I am just going to do a universal selector and say hey, give me all of the first child elements on the page. So I am just going to go ahead and do an *:first child and what I am going to do there is just go ahead and create property inside that, that says color red.

Okay. Fair enough. So if I save this and again preview this in a browser, I get to see some very interesting things here. Everything that's considered to be a first child is now targeted, including the first div tag. So the first div tag is a first child of the body tag, this heading is the first child of this div tag, and this heading is the first child of the third div tag. So we can see that it is accurately targeting all of the first children, including those larger block level elements. Okay. I am going to copy this and comment it out.

The reason I am copying it is because it's just going to make it little bit easier for me with my next selector, because I am just going to change the selector itself. Now the next thing I am going to do is I am going to target all of the heading 1s when they are the first child. So I am going to change that universal selector to h1:first child. Again, I can save and test this and I can see indeed all of the heading 1s have been selected because they are all on the first child inside their respective div tag. What if I just wanted target the first paragraphs inside the div tags? Obviously, first-child isn't letting me do that.

So again, I'm going to copy this, comment it out, and then just sort of paste it. Again you can just modify the selector if you want. You don't necessarily have to comment them out the way I am doing. So again if I say p:first-child and save that and test it, no targeting going on whatsoever. The reason for that? Paragraphs are never the first child. So I am going to modify this. Instead of saying first-child, why don't I just say first-of-type and do it that way? So instead of saying first child, I am going to say p:first-of-type.

Now if I save that and preview that, again now the first paragraph inside each div tag is indeed being targeted, something that first child couldn't be for me. Cool! Now let's take a look at some of the last-child selectors. I am going to go ahead again, copy this, comment it out, and paste it. What if we said p:last-child? Let's save that. Well, now if I test this in a browser, I can see that only where the paragraph is the last child inside of the div tag is it targeted.

So only when a paragraph is going to be a last child would I be targeting it. Let's change that up a little bit. I am going to copy this, comment it out, paste it. And what if I say h2:last-of-type. So again, instead of just saying last- child, we are going to say last-of-type. So now if I save this and preview it, now each last heading 2 and a div tag, even if it's only one, will be selected. So you can see here it's targeted two of those, ignoring this one because it is not the last heading 2.

Finally, let's check our only child. So I am going to go ahead and copy this, comment it out, and paste it. Essentially here, I am just going to do paragraph only-child. I am going to save that and preview it, and you can see it doesn't target anything. Well, that's because there is never a parent element here that only has a paragraph in it and nothing else. But if I modify this to only-of-type and save and test that, now we can see that there is a div tag that has only one paragraph in it and that is successfully targeted.

First, last, and only structural selectors are extremely useful, especially for sites that contain a lot of dynamic contents. So if you have paragraphs and div sections and contents being dynamically generated, a lot of times these can really help you say that hey, the first heading inside this div tag, no matter what it is, gets this styling. Now if you decide to use these selectors, keep in mind that Internet Explorer has fairly weak support for them and if you are going to attach critical styling to them, you may have to provide an alternate or fallback means of applying those styles.

Find answers to the most frequently asked questions about CSS3 First Look.


Expand all | Collapse all
Please wait...
Q: I'm following along with the video "Transparency in CSS3".  James shows us how to achieve transparency in Internet Explorer by going to Kimili.com and entering a HSLA value to generate code for transparency.

Here that code:

background: transparent;-ms-filter: "progid:DXImageTransform.Microsoft.gradient(startColorstr=#BF0E0C0B,endColorstr=#BF0E0C0B)"; /* IE8 */
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr=#BF0E0C0B,endColorstr=#BF0E0C0B); /* IE6 & 7 */ zoom: 1;

When this code is added to my HTML file it removes transparency on browsers that do in fact support it. So I'm left with NO transparency. Why?
A: The problem is in the filter code. If the IE background is called last, the first "transparent" declaration will remove all previous colors, regardless of browser. To resolve this, place the rule inside a conditional comment for IE or remove the "transparent" declaration at the front of the rule.
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 CSS3 First Look.

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


OK

Course retiring soon

CSS3 First Look will be retired from the lynda.com library on April 24, 2014. Training videos and exercise files will no longer be available, but the course will still appear in your course history and certificates of completion.


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

Terms and conditions of use

We've updated our terms and conditions (now called terms of service).Go
Review and accept our updated terms of service.