HTML and CSS Reference
Q: Why isn't there a table column
element? That seems pretty important.
A: The designers of HTML decided to
let you specify tables by row, rather than
by column. But notice that by specifying
each row's <td> elements, you are implicitly
specifying each column anyway.
your layouts today. Using tables for layout
is notoriously hard to get right and difficult
to maintain. Instead, it's much better to
use CSS table display to get the benefits
of a table layout without actually creating
an HTML table (this is how we styled the
Starbuzz page in Chapter 11). Tell your
friend that his technique is old school, and
he needs to get up to speed with the right
way to do layout: CSS with HTML.
Tables give you a way
to specify tabular data
in your HTML.
Q: What happens if I have a row that
doesn't have enough elements? In other
words, I've got fewer things than the
number of columns in the table?
A: The easiest way to deal with that is to
just leave the content of the data cell empty;
in other words, you write <td></td>. If you
leave out the data cell, then the table won't
line up properly, so all the data cells have to
be there, even if they are empty.
Tables consist of data
cells within rows.
Columns are implicitly
defined within the
Q: Isn't a table all about presentation?
What happened to presentation versus
A: Not really. With tables, you are
specifying the relationships between tabular
data items. We'll use CSS to alter the
presentation of the table.
Q: How do HTML tables relate to CSS
A: HTML tables allow you to specify
the structure of a table using markup while
CSS table display gives you a way to
display block-level elements in a table-like
presentation. Think about it this way, when
you really need to create tabular data in your
page, use tables (and we'll see how to style
these in a bit); however, when you just need
to make use of a table-like presentation with
other types of content, then you can use a
CSS table display layout.
The number of
columns in your table
will be the number of
data cells you have in
Q: What if I want my table headings to
be down the left side of the table, instead
of across the top; can I do that?
A: Yes, you certainly can. You just need
to put your table heading elements in each
row instead of all in the first row. If your <th>
element is the first item in each row, then the
first column will consist of all table headings.
Q: My friend showed me a cool trick
where he did all his page layout right
within a table. He didn't even have to use
A: Go straight to CSS jail. Do not pass
go; do not collect $200.
In general, tables are
not meant to be used
for presentation; that's
the job of CSS.
Q: Can we use CSS table display to
style HTML tables?
A: Well, you don't really need to. Why?
Because you're already creating a tabular
structure with HTML, so, as you'll see,
you can use simple CSS to style the table
however you like.
Using tables for layout was commonly done
in the HTML era before CSS, when, frankly,
there was no better way to do complex
layouts. However, it is a poor way to do