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

XHTML and HTML Essential Training

Aligning images with tables


From:

XHTML and HTML Essential Training

with Bill Weinman

Video: Aligning images with tables

So, we've looked at how you present tabular data using tables, and now we're going to look at how you align visual elements using a table, how you assemble pieces of an image so it all looks like one image. This is a very common technique. I still prefer to do it with tables. I think it's easier, and I think it falls well within what tables were designed to do. So, this is how you align visual elements using tables. If you're interested in how to do this using CSS, I'm working on another course on CSS positioning, which you will also find on lynda.com, which will show how to do it that way.
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

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...
XHTML and HTML Essential Training
4h 44m Beginner Jul 28, 2009

Viewers: in countries Watching now:

In XHTML and HTML Essential Training, Bill Weinman helps designers and coders understand XHTML and HTML. In the process, Bill covers document structure, block and inline-level tags, floating images, controlling white space, phrase and font markup, and tables and frames. He even provides a good introduction to CSS. Bill offers step-by-step guidance for building a complete working web site. Exercise files accompany the course.

Topics include:
  • Understanding the structure of an HTML or XHTML document
  • Creating and using templates
  • Controlling white space and line breaks
  • Making effective use of tables and frames
  • Flowing text around an image
  • Formatting tables with CSS
  • Creating web pages that work properly across platforms and devices
  • Reviewing a case study of a complete web site
Subjects:
Developer Web Web Design Web Foundations Programming Languages Web Development
Software:
HTML XHTML
Author:
Bill Weinman

Aligning images with tables

So, we've looked at how you present tabular data using tables, and now we're going to look at how you align visual elements using a table, how you assemble pieces of an image so it all looks like one image. This is a very common technique. I still prefer to do it with tables. I think it's easier, and I think it falls well within what tables were designed to do. So, this is how you align visual elements using tables. If you're interested in how to do this using CSS, I'm working on another course on CSS positioning, which you will also find on lynda.com, which will show how to do it that way.

In this case, we are doing this with tables, and this is how it's done. Here we have an XHTML document with a table, and this is the table. You'll notice it says border=0, cellspacing=0, cellpadding=0. Again, you can do this part with CSS, if you prefer, but the idea is that you want to turn off all of that spacing stuff that tables normally do, so that the images butt right up against each other and create one big image. So, here is the nine parts of the image. There is three rows, and each row has three cells, and there are all the images.

If we look at it on the browser, these are the nine images. If I just right-click on one of them and say View Image, you'll see that part of the image, and you'll see that that's part two of the image, and go back, and there we have the whole image. I'm going to go ahead and turn on the borders in the table, so that you can see that. I'll save here in the editor and go back to the browser and reload. Now we have the borders turned on, so you can see how the image is divided. You have nine parts of the image. This part here is entirely white, so is that.

But there are the nine parts of the image, and you'll see this was broken apart because it has parts that are animated GIFs. That makes it easier, so you don't have to animate the entire thing; you can animate just the parts of it. Anyway, that's how that's done. Now, you'll notice that this has bad version, and there is a reason for that. Let me go ahead and turn off the border. Again in the editor, it will save, and now I'll reload this in the browser. Actually, this browser no longer shows this problem. This is Firefox, and Firefox thinks it's smart enough to know what I mean instead of what I say.

So it's putting the image all close to each other, even though in the document, I've done it wrong and it's not supposed to show up that way. You'll see that the cutapart and the cutapart (bad version) both look the same. For some purposes, one could appreciate that. The problem is that it hides a problem which happens to show up in other browsers. So I have another browser here. This is the Internet Explorer browser. You'll notice in Internet Explorer that it actually shows gaps between the images. It used to show gaps vertically as well, and in this case it's only showing gaps horizontally.

Older versions of all the browsers used to show gaps in between the images as well. This is because there actually are gaps in between the images in the HTML. Let's take a look at the XHTML document again. You'll notice each of my table cells, TR for the rows, you have TDs for the individual data cells. Each of my cells has the TD above, the TD below, and the image in-between. So, what's wrong with this picture? Well, you'll see that there is space before the image, and there is another space because, remember that the browser considers a new line another space.

So we have, four, six, seven spaces or so here that are all getting folded into one space, because that's what the browser does. And here after the image as well, we have more spaces. If we want the images to be butted right up against each other, if we want the images to not have any space between them, then we need to not put any space in the source document in the XHTML. So, here is cutapart_good, and these are in your exercise files. You'll see how this is done. We have the TR, we have the rows. You'll see this all fits on one page really nicely, too.

It still looks very nice. We have the TD for the data cell, and there is no space at all around the image. There is the image, and it's right up against the TD and right up against the TD. Now, the way that tables work, this space here should be okay, because the browser isn't supposed to display that. That doesn't appear anywhere on the screen. The only content in a table that's actually supposed to appear on the screen is the content inside the data cells and inside the heading cells as well. So, the data cell--this is what you want--has got the image in it and nothing else whatsoever, no spaces.

So we have TD, TD, TD, all with those spaces, no spaces in this table at all. So if we look at the cutapart_good, in Internet Explorer, we'll see that it has no spaces at all. So, that's how that's done. So, this is how you take an image that's in pieces and you assemble it using tables. This is the correct way to do it. You have your table, border off, cellspacing off, cellpadding off and you simply put the images in your table data rows, and in your table data columns.

It all comes together really nicely. It looks nice in Internet Explorer, and it looks nice in Firefox as well. So that's how you assemble an image using tables.

Find answers to the most frequently asked questions about XHTML and HTML Essential Training.


Expand all | Collapse all
Please wait...
Q: In this title, the instructor uses tables to create a website design. Is there a way to create this same layout with CSS?
A: This course will be updated to include CSS-based layout techniques within
the next few months. In the meantime, please see Bill's <a href="
http://www.lynda.com/home/DisplayCourse.aspx?lpk2=52341">CSS for
Developers</a> title for more information on coding with CSS.
Q: In the "Understanding the structure of an XHTML document" movie in Chapter 1, where does the "Roses are red," etc, text come from? I don't see it in the code.
A: Notice the <frame src="??"> tags. These reference other .html files that contain the content of the various frames. Details about how frames work can be found in Chapter 6 of the course.
Q: In this title, the instructor uses tables to create a website design. Is there a way to create this same layout with CSS?
A: This course will be updated to include CSS-based layout techniques later in 2012. In the meantime, please see Bill's CSS for Developers title for more information on coding with CSS.
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 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
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