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

Formatting tables with CSS

From: XHTML and HTML Essential Training

Video: Formatting tables with CSS

In our last lesson, we looked at how tables work in XHTML and HTML. In this lesson we're going to look at how you can format your tables using CSS. CSS stands for Cascading Style Sheets and that's the technology that's used on the web for formatting web pages and making them to look prettier than the default might be if you didn't have any styling at all. Of course, a lot of which you do with CSS, you can do with attributes in XHTML and HTML. Most people recommend that you use CSS. I'm going to tell you why CSS is better.

Formatting tables with CSS

In our last lesson, we looked at how tables work in XHTML and HTML. In this lesson we're going to look at how you can format your tables using CSS. CSS stands for Cascading Style Sheets and that's the technology that's used on the web for formatting web pages and making them to look prettier than the default might be if you didn't have any styling at all. Of course, a lot of which you do with CSS, you can do with attributes in XHTML and HTML. Most people recommend that you use CSS. I'm going to tell you why CSS is better.

In a nutshell, using CSS, you can name your styles and you can then apply those styles to a number of different places within your document. Then if you need to change them, you can simply change it in one place and that changes all across the document. It's a lot easier to manage your styles and it's a lot easier to apply them in an organized fashion. We'll see some examples of that in this lesson. So let's get into it. Here is the table, here in this table- css.html document and this is our editor here on the top and this is the browser here on the bottom.

So you can see it's the same table from our last lesson, which looked like this except that it's got some style applied to it. So it's a bit more attractive and in my opinion it's a bit easier to read as well. So here is the XHTML file and this is the CSS file over here in this tab and we'll be looking at this in a little bit of detail as we get into the lesson. For now, let's look at the XHTML. You see there is the table and the table ends down here at the bottom. It looks very much like the table we did in our last lesson with a few significant differences.

We have these class attributes here for applying the styles and we'll see how that works in just a moment. So, here's the table and over here in the CSS, you'll notice that we have some style applied to the body and we have some style applied to the table, we have some style applied to the caption. This is an example of Cascading Style Sheets, CSS. What the cascading means in CSS is the styles apply on top of styles. So, for example, we have some style applied to the body, the background is white, you see the FFF means white, the font is set to Tahoma or Sans-serif if Tahoma is not available on your system.

So we see that the font throughout the document is this Tahoma font and the font size is set too, because Tahoma tends to be a little bit big, so I made it a little bit smaller. These are just my choices, of course, you can make your own choices and your own style sheet, but I like them like that. So that's applied to entire document. Even to these elements within the document, it's still applied. So the table itself has a border. It has a border style. It has a border color. The background of the table is this white, because that's the style that was applied to the background of the entire document.

If I change this from white and make it-- well, I don't know. Say FCC, which is sort of a reddish color, save that and reload. We see that applies to the entire document and it applies to the background of the table there. Now there are certain table cells where I've set the color to be grey and to be white. Of course, those get their own styles, but this is an example of the cascading, because the entire document has this color. That's also applied to the elements within the document, like for instance in this table.

I'll change that back. We'll see some more examples of this as we go on. It should be really clear by the time we're done. Save that and reload. Now, if we look over here at the caption, we see it says My Favorite Albums, and it has the caption tag. If we look in CSS, we'll see that we have a caption selector here on this style and that applies to all the caption tags that it will find in the document, which happens to be 1. It applies this bold style. The font is the Tahoma font because that was set up in the body.

If I were to change that to something else like, oh, I don't know, Comic Sans MS, save and reload. Then we see the entire document changes to Comic Sans MS including even the caption where we have caption set to bold. It's picking up that font from the body. This is the cascading in Cascading Style Sheets. Put this back to Tahoma and save and reload and that changes it everywhere in the document.

Now, let's take a look at the table row and the table heading. Now, we'll notice in the Cascading Style Sheets, table row does not have a style attached to it. Table heading has this align equals left, font-weight, bold and color equals 666, which is a medium grey, and we'll see here that the table heading in this row here, it's got the bold.

It's got the left-align. You will remember in our last document, we'll take a look at that, that the table headings were centered. I like them a lot better on the left. I think they read better on the left, they align better with the data on the left, so they look more like the headings on these tables. So it has these styles applied, of course, on top of the styles are applied to the body of the document. We have this row here which has the table row class equals grey and then it's got the data cells with their own classes: artist, title and comment. This is another example of cascading.

You'll see over here we have tr.grey, tr.white and td.artist and td.title. These are selectors with classes, so tr. grey means a TR tag with a grey class. We'll look over here. We have a TR tag with a grey class. So wherever the document sees tr class = grey and there is another instance of it here two rows down, then that class will be applied from here.

tr.grey has a background color set to this light grey. So all the cells within that row, we have TD, TD, TD, will all get that grey background. You'll see here they are grey, grey, grey. So that gets applied to these cells. Even though these cells have their own class, this one is artist, this one is title, this one is comment, these data classes get applied on top of the row class because these elements are within the TR container.

So the TR is wrapped around these data cells and so this class gets applied first because it's in the outer box and these classes get applied on top of that because they're inner boxes. So it looks like this on the page. You have the grey all the way across and then you have this Artist class, which has got this maroon color, this Title class, which is italic, and this Comment class. You see here the Comment class has a blue color to it. So these classes here, td.artist, td. title, td.comment, they get applied after the row classes.

It doesn't matter where they are in the document here. I could move these, let's drag them up here and now they're above, save that and reload here. It doesn't change. They are still applied in the same order; you've got the grey and you've got the other. That's because it's not what order they are in, in the file. It's how they appear in the document. It's what container contains something else. So I'm going to put this back just because I like it that way. Let's save it and reload and we'll see that this is still how we expect it to be.

So the Artist class, the Title class, the Comment class, these apply to the fonts. We have a color, we have italic, we have another color and these get applied on top of the row classes. So in a nutshell, that's how it works. It's really easy to do by using the classes in this way, like for instance if I wanted to change this grey and make it maybe a lighter grey, I'll just type an EEE instead and save it. It applies in all of these different places throughout the document. You see now we have this very light grey.

Hopefully, you can see it on your screen. I can barely see it on mine. That it applies all throughout the document. I only need to change it in one place, or make it maybe a little bit bluish, save that and reload. We have a slightly bluish grey. So change this in one place and it applies throughout the document and that really is the power of Cascading Style Sheets right there. So this is how you can format a table to make it attractive using CSS. You see here's what our table looks like before, very plain. That's the defaults for the HTML. That's how it was originally envisioned, so that they could put tabular data in a document.

This is what you can do using CSS to make it more readable and more attractive.

Show transcript

This video is part of

Image for XHTML and HTML Essential Training
XHTML and HTML Essential Training

59 video lessons · 80428 viewers

Bill Weinman
Author

 
Expand all | Collapse all
  1. 5m 10s
    1. Welcome
      1m 16s
    2. Using the exercise files
      1m 23s
    3. Choosing a text editor
      2m 31s
  2. 15m 46s
    1. Introducing HTML and XHTML
      2m 53s
    2. Understanding versions of HTML and XHTML
      2m 25s
    3. Exploring a simple XHTML page
      4m 47s
    4. Understanding the structure of an XHTML document
      2m 58s
    5. Understanding document containers
      54s
    6. Creating and using templates
      1m 49s
  3. 42m 4s
    1. Understanding how empty space is formatted in XHTML
      2m 42s
    2. Using paragraph tags
      2m 42s
    3. Aligning paragraphs
      2m 49s
    4. Understanding block-level and inline tags
      1m 24s
    5. Controlling line breaks and spaces
      5m 43s
    6. Formatting text with phrase element tags
      3m 28s
    7. Formatting text with font markup elements
      3m 24s
    8. Adding document structure with headings
      3m 25s
    9. Formatting quotations and quote marks
      2m 19s
    10. Preserving pre-formatted text
      1m 30s
    11. Selecting a typeface
      4m 33s
    12. Selecting a type size
      2m 11s
    13. Using ordered and unordered lists
      5m 54s
  4. 7m 48s
    1. Using inline images
      3m 17s
    2. Flowing text around an image
      2m 4s
    3. Breaking lines around an image
      2m 27s
  5. 22m 34s
    1. Working with hyperlinks
      7m 46s
    2. Using relative URLs
      3m 5s
    3. Specifying a base URL
      2m 4s
    4. Linking within a page using fragments
      4m 28s
    5. Creating image links
      5m 11s
  6. 22m 56s
    1. Introducing tables
      4m 37s
    2. Formatting tables with CSS
      8m 50s
    3. Aligning images with tables
      5m 7s
    4. Reviewing an alternative solution using CSS
      4m 22s
  7. 14m 31s
    1. Introducing frames
      7m 56s
    2. Hiding frame borders
      3m 15s
    3. Creating inline frames using iFrame
      3m 20s
  8. 20m 50s
    1. Introducing forms: part 1
      10m 37s
    2. Introducing forms: part 2
      7m 45s
    3. Using CGI with forms
      2m 28s
  9. 25m 42s
    1. Introducing CSS
      3m 11s
    2. Understanding levels of inheritance
      6m 10s
    3. Learning CSS syntax
      11m 23s
    4. Using units of measure in CSS
      4m 58s
  10. 1h 45m
    1. Comparing table layout and CSS layout
      1m 25s
    2. Exploring the finished web site
      2m 37s
    3. Building a document header
      8m 18s
    4. Placing a banner and a contact button
      8m 13s
    5. Laying out a main menu
      6m 55s
    6. Creating a layout template: main body area
      13m 31s
    7. Creating a layout template: sidebar area
      5m 17s
    8. Creating a layout template: footer content
      4m 46s
    9. Building a main home page: main body content
      11m 24s
    10. Building a main home page: sidebar content
      8m 52s
    11. Creating a page with a menu, graphics, and formatted links
      13m 26s
    12. Creating a page containing an ordered list
      6m 44s
    13. Creating a page containing video
      10m 45s
    14. Touring the finished site
      3m 45s
  11. 53s
    1. Goodbye
      53s

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 XHTML and HTML 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.