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

Adding content to tables

From: Up and Running with HTML

Video: Adding content to tables

Tables are amazingly flexible in terms of what types of content they can hold. In fact, it's probably easier for me to just list a things a table cell can't hold rather than what it can. Just to give you some idea, table cells can hold text, paragraphs, headings, div tags, images, video, and even more complex structures like additional tables. Let's explore some of this as we add content to our own table. Now I have tables.htm open. And we really are picking up right where we left off in last exercise, but I have open it up from 05_02, because if you notice down below that table structure, I've got some content that we're going to move into our table here in just a moment.

Adding content to tables

Tables are amazingly flexible in terms of what types of content they can hold. In fact, it's probably easier for me to just list a things a table cell can't hold rather than what it can. Just to give you some idea, table cells can hold text, paragraphs, headings, div tags, images, video, and even more complex structures like additional tables. Let's explore some of this as we add content to our own table. Now I have tables.htm open. And we really are picking up right where we left off in last exercise, but I have open it up from 05_02, because if you notice down below that table structure, I've got some content that we're going to move into our table here in just a moment.

Well, the first thing I want to focus on is what type of content can a table cell hold? So I'm going to go to the first table cell, which is this initial TD tag right there, and I'm just going to type in "I can be almost anything." So it's a very self-affirming table. Save that, go back to my browser and refresh page so I'm testing in the browser, and indeed now I can see it. I can be almost anything, as our table says. Now, we still can't see the underlying table structure, so I'm going to use an attribute on our table that's going to help us out here.

I'm going to go back into my code, and inside the opening table tag I'm going to set border for the table to 1. So if I save that, go back in and preview that, now we can see sort of that default border. Now, to be honest with you, most of the time people are going to want to control borders through the use of CSS styles, but that attribute is still supported across multiple browsers. It still exists in HTML5, so it's not going away anytime soon. If you ever want to use the browser's default border, you could do that by just giving it a border of 1.

I want to go back to the text here, "I can be almost anything." Well, right now it's just text inside a table cell, but if I wrap a paragraph tag around it--let's save that and go back in our browser-- it looks almost the same. But I don't know if you can see this or not, but a little bit of extra space is now appearing above and below the text, and the reason for that is paragraphs have their own default margins that browsers apply to them, which is why we have space between two paragraphs, and now the table is reflecting that.

So, one of the things that you need to be careful about if you begin the place other HTML elements inside of table cells is it's going to have an effect. I mean if I change this to h1, for example, you can see that the table is just going to display at as an h1 inside the table. Notice that the table is flexing as the content inside of it changes, and that's really a default behavior of tables in HTML: they're going to stretch or contract to fit their content unless you tell them to do otherwise. Now, that can sometimes cause some awkwardness in terms of spacing. If I scroll down, I can see that I have a paragraph here in this comment where it says, "Data for table." I'm going to go ahead and cut that paragraph and then paste that into the second table cell.

Now, if I save this, go back into my browser, and refresh, check out what happened to our table. Now, it stretches the entire width of the page. The heading doesn't have quite as much room as it had before because this paragraph is taking up so much room. So, through the use of styles and other attributes, we can restrict the width of these table cells, but for the most part, if you place content inside of a table cell, that table cells is just going to expand to hold that content. And this, again, depends on sort of what's in there. You'll notice for example in the 05_02 folder I have some images.

So if I chose to place an image in this--so I'm just going to use an image tag and I'm going to set the source attribute. I need to go inside the _images directory and then I need to find the file flower_400.jpg. Now, I know I told you earlier that you should always have alt text with your images, so forgive me for not putting it in there, just for brevity's sake. So if I go back in, preview that, now you can see this image is taking up so much room. Also, the table cell is going stretch only for width but height as well. You can see this table cell is stretching to fit the entire height of the image.

Now that also means that the remaining table cells in that row are going to stretch as well, so all the table cells within a row will be as tall as the tallest cell. If it's stretching for content, the other ones are going to have this empty area in it now as well. So, as you're planning your tables, you need to start thinking about that and say "okay, you know do I have an image maybe that fits a little bit better with that content, and would it make better sense to use that instead?" So as you're planning your tables, you really need to think about the relationship of the data to each other.

We're not really going to use any of that. The data that we're going to use for our table is down here in these comments. So we got Row 1, and following that we have the contents for table cell 1, table cell 2, table cell 3, and then we can move to Row 2 and do the same thing. I'm not going to bore you with making you watch me do all of this, but what I am going to do is I'm going to empty the table cells and I'm just going to show you the first row-- here we go--so that you guys can see an example of what I'm going to be doing and do this for your own tables if you're following along with me with your own the exercise files.

So I'm going to cut Row 1, the word Tag, I'm going to cut that. I'm going to paste that into the first table cell. And I'm going to do the same thing: I want to cut that and then paste that into the second table cell. I'm sure you guys can see where this is going, right? I am going to take the third one, cut it, and then paste that into the third table cell. Now I'm just going to keep doing that until my table is filled all the way with the data that I have here. And boom, I'm done. Now, if I save this and I go back into my browser and refresh this, you can kind of see it's pretty simple. We just have text inside each of the table cells.

Even though ours is simple, you can have complex formatting inside of the table cells, as we saw it earlier as we mess around with headings and paragraphs and things like that. But even though you can do that, you probably won't need to do it very often at all. You should avoid any unnecessary formatting within tables if at all possible, so that you can remove as many barriers between your users and the data.

Show transcript

This video is part of

Image for Up and Running with HTML
Up and Running with HTML

49 video lessons · 27575 viewers

James Williamson
Author

 
Expand all | Collapse all
  1. 2m 12s
    1. Welcome
      55s
    2. Using the exercise files
      1m 17s
  2. 29m 30s
    1. Learning HTML
      2m 47s
    2. Choosing a code editor
      5m 2s
    3. Exploring basic HTML syntax
      8m 18s
    4. Do I need to learn HTML5?
      5m 6s
    5. Exploring HTML references
      8m 17s
  3. 35m 40s
    1. Exploring an HTML document
      5m 19s
    2. Working with doctype declarations
      4m 3s
    3. Examining the document head
      8m 20s
    4. Looking at the document body
      3m 21s
    5. Adding document structure
      8m 52s
    6. Lab: Coding a basic page
      3m 9s
    7. Solution: Coding a basic page
      2m 36s
  4. 1h 23m
    1. How does HTML format text?
      5m 51s
    2. Adding headings
      7m 24s
    3. Formatting paragraphs
      4m 54s
    4. Controlling line breaks
      3m 50s
    5. Creating lists
      10m 37s
    6. Emphasizing text
      6m 42s
    7. Displaying special characters
      5m 8s
    8. Controlling whitespace
      4m 35s
    9. Inserting images
      9m 20s
    10. Lab: Controlling page content
      13m 57s
    11. Solution: Controlling page content
      10m 55s
  5. 31m 54s
    1. Linking to pages within your site
      6m 45s
    2. Linking to external pages
      3m 2s
    3. Linking to downloadable resources
      2m 25s
    4. Linking to page regions
      8m 0s
    5. Lab: Creating Links
      5m 57s
    6. Solution: Creating Links
      5m 45s
  6. 40m 27s
    1. Examining basic table structure
      5m 10s
    2. Adding content to tables
      6m 20s
    3. Setting table attributes
      7m 42s
    4. Adding table captions
      4m 3s
    5. Defining table headers
      2m 13s
    6. Making table data accessible
      5m 46s
    7. Lab: Building tables
      4m 13s
    8. Solution: Building tables
      5m 0s
  7. 43m 23s
    1. Understanding the relationship between HTML and CSS
      4m 58s
    2. Creating inline styles
      4m 53s
    3. Exploring the style element
      5m 13s
    4. Basic font styling
      9m 24s
    5. Changing color
      4m 55s
    6. Taking styles further
      5m 24s
    7. Lab: Controlling basic styles
      5m 10s
    8. Solution: Controlling basic styles
      3m 26s
  8. 5m 44s
    1. Next steps
      2m 56s
    2. Additional resources
      2m 48s

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 Up and Running with HTML.

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


OK

Course retiring soon

Up and Running with HTML will be retired from the lynda.com library on October 31, 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. For updated training, check out HTML Essential Training in the lynda.com Online Training Library.


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