Easy-to-follow video tutorials help you learn software, creative, and business skills.Become a member

Styling alternate rows

From: Dreamweaver CS6 Essential Training

Video: Styling alternate rows

Although, our table isn't that large, the final version of the page will actually have multiple tables stacked one on top of the other. Anytime users are faced with a long vertical region of tabular data, it's a good idea to give them some type of visual aid to assist them with reading it. For our semester requirement tables we are first going to finish the basic styling of the table and then make that data a little easier to read by creating alternating background colors within the rows. So I am still working on the graphic-design.htm file. Now I have opened this one up from 09_ 05 folder, but to be honest with you, if you just wanted to pick it up and continue to work from the previous exercise, you can certainly do that.

Styling alternate rows

Although, our table isn't that large, the final version of the page will actually have multiple tables stacked one on top of the other. Anytime users are faced with a long vertical region of tabular data, it's a good idea to give them some type of visual aid to assist them with reading it. For our semester requirement tables we are first going to finish the basic styling of the table and then make that data a little easier to read by creating alternating background colors within the rows. So I am still working on the graphic-design.htm file. Now I have opened this one up from 09_ 05 folder, but to be honest with you, if you just wanted to pick it up and continue to work from the previous exercise, you can certainly do that.

I have my screen setup the same way. I have a Split screen view between Code and Design. The Design View has Live View enabled, so that I can see the changes as they are going to be rendered into my table and I'm focusing on the table styles right around line 483 or so. Now one of the reasons why we were at such a good stopping point in the previous excise is because I wanted to introduce you guys in this movie to some of the new selectors in the CSS Level 3 selector specification. Now they are not really new, people have been using them for a while now and their support among modern browsers is really, really good, but they're still newish enough to where a lot of web designers aren't familiar with them.

So the first thing that I'd like to do is I'd love to control if I could the width of these columns. Now there's a couple of different ways that you can do that. You could create a class and go ahead and tell the table cells, such as the table header cell to be a certain width. If one cell within a column is a certain width, then all the rest of them will follow. So I don't necessarily need to apply that type of class to every single table cell in a column. However, even that is pretty inefficient, because you have to go to the trouble of applying class to the table cell, and you have to deal with the fact that you're applying some non-semantic class attributes.

So what I love about some of these new selectors is they allow us to target elements based upon their relationship to their siblings and their parents and that's a really powerful way of targeting things especially within structured elements like tables. So I am going to go over to my Code and I am going to create a new selector and this time I am going to target article th. Now that's nothing new, we know that that will target any table header cell within the article that we are looking at. But I'm going to add a pseudo-class selector to this and to do that, I type in a colon that adds the pseudo-class selector and then I am going to type in first-child.

So what that's saying is go inside your article and find any table header that is the first child of its parent. In this case it's going to target this table header right here because it's the first table header inside the table itself. So now I'm able to go ahead and set a width on that, I am just going to set the width to 75% and I'll save my file and when I click over here, you can see, well, it didn't really need to resize that much, did it? But it did resize and now because I don't know how long all these different course names are going to be and I know that the credit hours are pretty small, I can just go ahead and expand that to fit 75% of the Width and now I have got more room for these guys and less of the room over here and I really again don't need that much of it. Okay.

Now another thing I'm going to do is I am going to tackle the alignment of the text inside the table. Now I am not just talking about left align, right align that sort of thing, but what's really nice about table cells is that you can also tackle the vertical alignment of content. So I am going to go down to the next line and I am going to type in article th, article td. So this is a group selector and this allows us to basically group two elements together at the same time and style both of them.

So we are styling any table data cell found within an article and any table header cells found within an article. So this should apply to all the cells in our table. And what I am going to do here is I am going to type in vertical-align and I want that to be middle. Now I am going to save this and then when I click back on my table, I am not really going to see anything right now, because we don't have any padding top or bottom, but do notice what it did in the headers. You can tell the text is sort of centered vertically if you will, right in the middle of the table cell and that's exactly what I wanted.

Now speaking of padding, we do need to add some to our individual table cells themselves, so I am going to go down to the next line and type in, article td and then inside that I am just going to go ahead and do a padding of .4ems top and bottom, space, 1em right and left. So when you're using two values in that shorthand notation, what that does for you is the first value is top and bottom, the second value is right and left, and now when I click on my table to refresh that, you can see what's happening with the table cell information. I have some space above and below it, I also have some space to the right and to the left of it, and because we just did a vertical line, it's sort of floating there in the middle, which is very nice.

Now another thing I would like to do is I would like to take the text in the credit hours and I would like to center that underneath the actual text, so that it looks a little bit nicer in there. I also like to bold that text. Now, in our table we already have some text that's bold, we took the course IDs here and we wrapped those in a strong tag, so you might think, well, why don't we just go ahead and wrap these in the strong tag as well. Well, actually wrapping these in a strong tag is somebody structural that we did. We wanted to call attention to those. Essentially, for the credit hours, I just want to do that as a visual thing, I don't necessarily need to draw the reader's attention to it.

A lot of times that is a judgment call and in this case, I'm thinking that for the credit hours, we could probably do a little bit better using CSS, than we can through these with strong tag. Now the next thing is in terms of the formatting requirements for that, we just need to target only these table cells. That can become a little bit difficult, but then again this is where pseudo-class selectors can come in and help us. So just below the article td, I am going to write the following selector, type in, article td:nth-child, and I am going to pass into that (even).

Now this is a pretty complex selector. If you've ever worked with nth-child selectors before, you know how much you can do with them, but if you haven't, let me talk to you a little bit about nth-child. So nth-child selectors allow you to choose an element based on its pattern within its parent. So essentially what we are passing into this is we are saying, nth-child whenever a table data is the even number within a parent, select that, and if you think about actual td tags themselves, this is our first one, this is the second, third, fourth, fifth, sixth, I think you get the idea.

So this column, they are all going to be even numbers. So that allows me to write a selector that targets just this column, not this column, and I don't have to do any class applications or write any class attributes, which is really nice. So inside this, I am just going to go ahead and type in font-weight: bold and text-align: center. So I am going to save that and click and you can see it centers the text within that column and it bolds it as well.

Now we are almost finished, but the last thing we want to do is we want to create these alternating colors, and again, nth-child selectors can assist us with that. So I am going to go down to the next line and actually you know what, I want to organize my style, so I want to move this up, because we are going to be targeting table rows. So I am going to go just below the existing table row selector and once again I am going to type in article tr, and then again, we are going to do nth-child(even). article tr:nth-child(even). Okay, so what's this going to target for me? Well, remember, it's doing every even number row, the first row would be your header, so it's going to start with this row, which is the second one, and then it's just going to jump each time ignore, target, ignore, target, ignore, target.

What's really nice about this in terms of an nth-child selector, I no longer have to worry about how many rows I am going to have in my table or assigning a class-attribute to every other row. That's impossible almost to do in dynamic tables, so this gives us a really nice ability to just target any table on the page and always know that I am going to have these alternating rows. So I am going to click inside of this and I am just going to type in background and then rgb and the color I am going to type in is 249, 228, 130.

Now it's going to be sort of a pale yellow color. If I save this and click inside of my table, you can see starting at the second row, that now becomes that sort of pale yellow color and then it alternates each timeout. So nth-child selectors are incredibly useful, especially for elements with repeating structures such as tables or lists. Now in our own table, we have used them to create alternating rows of colors and set the width of our table columns. Now if you have never worked with them before, be sure to explore the W3C Specification on CSS selectors, as they have a ton of more options for targeting page elements, than the ones that I've shown here.

Show transcript

This video is part of

Image for Dreamweaver CS6 Essential Training
Dreamweaver CS6 Essential Training

90 video lessons · 53436 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 1m 4s
    1. What is Dreamweaver?
      1m 4s
  2. 5m 44s
    1. Welcome
      1m 4s
    2. Using the exercise files
      2m 17s
    3. Learning web design
      2m 23s
  3. 1h 0m
    1. Looking at the Welcome screen
      5m 9s
    2. Exploring Windows and Mac interface differences
      5m 6s
    3. Arranging panels
      8m 44s
    4. Managing workspaces
      10m 14s
    5. Exploring the Application toolbar
      6m 21s
    6. Exploring the Document toolbar
      8m 47s
    7. Working with the Property inspector
      9m 30s
    8. Using the Insert panel
      6m 30s
  4. 53m 3s
    1. Understanding basic site structure
      3m 46s
    2. Exploring file naming conventions
      2m 10s
    3. Defining a new site
      5m 23s
    4. Managing files and folders
      7m 57s
    5. Adding remote servers
      7m 4s
    6. Uploading files
      12m 46s
    7. Previewing in browsers
      9m 11s
    8. Managing multiple sites
      4m 46s
  5. 36m 41s
    1. Creating new documents
      6m 49s
    2. Setting up new document preferences
      5m 30s
    3. Setting accessibility preferences
      6m 49s
    4. Working with starter pages
      4m 32s
    5. Managing starter pages
      13m 1s
  6. 37m 23s
    1. Getting text into Dreamweaver
      8m 43s
    2. Importing Word documents
      4m 6s
    3. Adding structure to text
      7m 35s
    4. Creating lists
      4m 35s
    5. Creating definition lists
      4m 0s
    6. Using the Quick Tag Editor
      8m 24s
  7. 44m 41s
    1. Exploring the Code toolbar
      5m 41s
    2. Setting code preferences
      7m 19s
    3. Using code hints
      8m 8s
    4. Wrapping tags
      5m 7s
    5. Adding comments
      6m 29s
    6. Using snippets
      7m 32s
    7. Formatting source code
      4m 25s
  8. 1h 19m
    1. Setting CSS preferences
      9m 32s
    2. An overview of the CSS Styles panel
      9m 23s
    3. Creating a new CSS rule
      6m 42s
    4. Using the CSS Rule Definition dialog
      7m 25s
    5. Organizing styles
      7m 22s
    6. Modifying style properties
      6m 17s
    7. Controlling CSS through the Property inspector
      6m 37s
    8. Attaching external style sheets
      5m 54s
    9. Using CSS visual aids
      7m 3s
    10. Using CSS Inspect
      6m 48s
    11. Using the Code Navigator
      6m 39s
  9. 1h 11m
    1. Managing assets in Dreamweaver
      7m 30s
    2. Setting external image editing preferences
      4m 26s
    3. Placing images on the page
      10m 12s
    4. Exploring Photoshop integration
      7m 17s
    5. Modifying Smart Objects
      9m 42s
    6. Modifying image properties
      8m 4s
    7. Styling images with CSS
      6m 45s
    8. Using background graphics
      7m 28s
    9. Positioning background graphics
      10m 10s
  10. 36m 23s
    1. Link basics
      3m 17s
    2. Setting site linking preferences
      2m 19s
    3. Creating links in Dreamweaver
      9m 17s
    4. Using absolute links
      3m 43s
    5. Using named anchors
      6m 41s
    6. Creating an email link
      5m 25s
    7. Creating CSS-based rollovers
      5m 41s
  11. 44m 30s
    1. Reviewing table structure
      5m 20s
    2. Importing tabular data
      6m 46s
    3. Creating accessible tables
      6m 11s
    4. Exploring basic table styling
      9m 42s
    5. Styling alternate rows
      8m 57s
    6. Creating custom table borders
      7m 34s
  12. 59m 15s
    1. Understanding how forms work
      2m 45s
    2. Reviewing form design
      3m 44s
    3. Creating accessible forms
      5m 16s
    4. Setting form properties
      2m 39s
    5. Using the fieldset and legend tags
      2m 52s
    6. Inserting text fields
      6m 56s
    7. Inserting list menu items
      7m 54s
    8. Inserting checkboxes
      4m 14s
    9. Inserting radio button groups
      3m 52s
    10. Inserting submit buttons
      2m 25s
    11. Exploring basic form styling
      8m 2s
    12. Exploring form element styling
      8m 36s
  13. 33m 25s
    1. Adding CSS3 transitions
      8m 29s
    2. Spry overview
      2m 44s
    3. Using Spry widgets
      3m 57s
    4. Adding Spry effects
      8m 1s
    5. Using the Widget Browser
      7m 4s
    6. Extending Dreamweaver
      3m 10s
  14. 1m 2s
    1. Additional resources
      1m 2s

Start learning today

Get unlimited access to all courses for just $25/month.

Become a member
Sometimes @lynda teaches me how to use a program and sometimes Lynda.com changes my life forever. @JosefShutter
@lynda lynda.com is an absolute life saver when it comes to learning todays software. Definitely recommend it! #higherlearning @Michael_Caraway
@lynda The best thing online! Your database of courses is great! To the mark and very helpful. Thanks! @ru22more
Got to create something yesterday I never thought I could do. #thanks @lynda @Ngventurella
I really do love @lynda as a learning platform. Never stop learning and developing, it’s probably our greatest gift as a species! @soundslikedavid
@lynda just subscribed to lynda.com all I can say its brilliant join now trust me @ButchSamurai
@lynda is an awesome resource. The membership is priceless if you take advantage of it. @diabetic_techie
One of the best decision I made this year. Buy a 1yr subscription to @lynda @cybercaptive
guys lynda.com (@lynda) is the best. So far I’ve learned Java, principles of OO programming, and now learning about MS project @lucasmitchell
Signed back up to @lynda dot com. I’ve missed it!! Proper geeking out right now! #timetolearn #geek @JayGodbold
Share a link to this course

What are exercise files?

Exercise files are the same files the author uses in the course. Save time by downloading the author's files instead of setting up your own files, and learn by following along with the instructor.

Can I take this course without the exercise files?

Yes! If you decide you would like the exercise files later, you can upgrade to a premium account any time.

Become a member Download sample files See plans and pricing

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.


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.

Join now "Already a member? Log in

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 Dreamweaver CS6 Essential Training.

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
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.

Are you sure you want to delete this note?

No

Your file was successfully uploaded.

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.