HTML The Definitive Guide (116 page)

Read HTML The Definitive Guide Online

Authors: Chuck Musciano Bill Kennedy

BOOK: HTML The Definitive Guide
9.6Mb size Format: txt, pdf, ePub

middle, although acceptable, has no real effect since it simply reiterates the default vertical alignment:














AlignmentTopBaselineCenterBottom
Baseline__
Another line
AAyy_AAyy_ AAyyAAyy

Figure 11.4: Effects of the valign attribute on table cell content alignment
You also may respecify the horizontal and vertical alignments for individual cells within a row (section
Section 11.2.4.1, "The align and valign attributes"). Use the alignment attributes in the
tag to specify the most common cell content justifications for the row (if not the default), and use a different align or valign attribute for those individual cells that deviate from the common alignment.

Table 11.1 contains the horizontal (
align) and vertical (valign) table cell-content attribute values and options. Values in parentheses are the defaults for the popular browsers.

Table 11.1: Horizontal and Vertical Table Cell-Content Attribute Values and Options

Attribute Netscape and Internet Explorer
Headers

Data

Left

(Left)

align

(Center)

Center

Right

Right

Justify[1]

Justifya

Chara

Chara

Top

Top

valign

(Center)

(Center)

Bottom

Bottom

Baseline

Baseline

[1] Value not yet supported.

11.2.3.2 The char and charoff attributes
Even simple word processors let you line up decimal points for numbers in a table. Up until the advent of the HTML 4.0 standard, the language was deficient in this feature. Now you may include the char attribute to indicate which letter in each of the table row's cells should be the axis for that alignment. You need not include a value with char. If you don't, the default character is language-based: it's a period in English, for example, and the comma in French. Include the char attribute and a single letter as its value to specify a different alignment character.

Use the charoff attribute and an integer number to specify the offset to the first occurrence of the alignment character on each line. If a line doesn't include the alignment character, it should be horizontally shifted to end at the alignment position.

The char and charoff attributes are new with HTML 4.0, and consequently not yet supported by any of the popular browsers. Nonetheless, you may someday use them to line up your decimals.

11.2.3.3 The bgcolor attribute

Like its relative for the

tag, the bgcolor attribute for the tag sets the background
color of the entire row.[2] Its value is either an RGB color value or a standard color name. Both the

syntax of color values and the acceptable color names are provided in Appendix F.

[2] Unlike

with Internet Explorer though, does not support a background image.

Every cell in the row will be given this background color. Individual cell colors can be changed by providing the bgcolor attribute for those cells.

11.2.3.4 The bordercolor, bordercolorlight, and bordercolordark attributes
Like their nonstandard brethren for the

tag, Internet Explorer lets you use these attributes to set the color of the borders within the current row.

Their values override any values set by the corresponding attribute in the containing

tag.

See the corresponding description of these extensions in Section 11.2.1.5, "The bordercolor,

bordercolorlight, and bordercolordark attributes" for details. Color values can be either an RGB color

value or a standard color name, both of which are described fully in
Appendix F.

11.2.3.5 The nowrap attribute

Browsers treat each table cell as though it were a browser window unto itself, flowing contents inside the cell as they would common body contents (although subject to special table-cell alignment properties). Accordingly, the browsers automatically wrap text lines to fill the allotted table cell space.

The nowrap attribute, when included in a table row, stops that normal word wrapping in all cells in that row. With nowrap, the browser assembles the contents of the cell onto a single line, unless you insert a
or

tag, which then forces a break so that the contents continue on a new line inside the table cell.

11.2.4 The

tags of an HTML table to create the cells and contents within the row. The tags operate similarly; the only real differences are that the browsers render header text - meant to entitle or otherwise describe table data - in boldface font style and that the default alignment of their respective contents may be different than for data. Data typically gets
left-justified by default; headers get centered (Table 11.1
).

; may be omitted Contains:

body_content

Used in:

tr_content

Like those available for the table row (

) tag, the table cell tags support a rich set of style and content-alignment attributes you may apply to a single data or header cell. These attributes override the default values for the current row. There are also special attributes that control the number of columns or rows a cell may span in the table. The
; see section Section 11.2.3, "The
Tag"
), except that when used with a
tag,
but does not affect the alignment of subsequent cells. See Table 11.1 for alignment details.

You may set the align attribute's value to left, right, or center, causing the browsers to align the cell contents against the left or right edge, or in the center of the cell, respectively. In addition, Internet Explorer supports a value of justify to fill each line of text so that it is flush to both sides of the cell. The valign attribute may have a value of top, bottom, middle, or baseline, telling the browser to align the cell's contents to the top or bottom edge, or in the center of the cell, or (Netscape only) to the baseline of the first line of text in other cells in the row.

11.2.4.2 The width attribute

Like its twin in the

and Tags
The
and tags go inside the
and

Function:

Define table data and header cells

Attributes:

ABBR NOWRAP

ALIGN ONCLICK

AXIS ONDBLCLICK

BACKGROUND

ONKEYDOWN

BGCOLOR ONKEYPRESS

BORDERCOLOR

ONKEYUP

BORDERCOLORDARK

ONMOUSEDOWN

BORDERCOLORLIGHT

ONMOUSEMOVE

CHAR ONMOUSEOUT

CHAROFF ONMOUSEOVER

CLASS ONMOUSEUP

COLSPAN ROWSPAN

DIR SCOPE

HEADERS STYLE

HEIGHT TITLE

ID VALIGN

LANG WIDTH

End tag:

or

and tags also accept the common table
attributes described in section Section 11.2.2, "Common Table Attributes"
.

The contents of the

and tags can be anything you might put in the body of an HTML

document, including text, images, forms, and so on - even another table. And, as described earlier, the browser automatically creates a table large enough, both vertically and horizontally, to display all the contents of any and all the cells.

If a particular row has fewer header or data items than other rows, the browser adds empty cells at the end to fill the row. If you need to make an empty cell before the end of a row, for instance, to indicate a missing data point, create a header or data cell with no content.

Empty cells look different than those containing data or headers if the table has borders: the empty cell will not be seemingly embossed onto the window, but instead is simply left blank. If you want to create an empty cell that has incised borders like all the other cells in your table, be sure to place a minimal amount of content in the cell: a single
tag, for instance.

11.2.4.1 The align and valign attributes
The align and valign attributes are identical to those of the same name for the table row tag (

or tag, they control the horizontal or vertical alignment of content in just the current cell. Their value overrides any alignment established by the respective align or valign attribute of the
tag that lets you widen a table, the width attribute for table cell tags lets you widen an individual cell and hence the entire column it occupies. You set the width to an integer number of pixels, or a percentage indicating the cell's width as a fraction of the table as a whole.

For example:


sets the current header cell's width, and hence the entire column of cells, to 400 pixels wide.

Alternatively:


creates a data cell whose column will occupy 40 percent of the entire table's width.

Since the extended browsers make all cells in a column the same width, you should place a width attribute in only one cell within a column, preferably the first instance of the cell in the first row, for source readability. If two or more cells in the same column happen to have width attributes, the widest one is honored. You can't make a column thinner than the minimum needed to display all of the cells in the column. So, if the browser determines that the column of cells needs to be at least 150

pixels wide to accommodate all the cells' contents, it will ignore a width attribute in one of the column's cell tags that attempts to make the cell only 100 pixels wide.

11.2.4.3 The height attribute

The height attribute lets you specify a minimum height, in pixels, for the current cell. Since all cells in a row have the same height, this attribute need only be specified on one cell in the row, preferably the first. If some other cell in the row needs to be taller to accommodate its contents, this attribute is ignored and all the cells in the row will be set to the larger size.

Other books

Marie Antoinette by Kathryn Lasky
The Colorman by Erika Wood
March (Calendar Girl #3) by Audrey Carlan
Barefoot Pirate by Sherwood Smith
Show No Mercy by Walkers, Bethany
Boulevard by Bill Guttentag

© 100 Vampire Novels 2015 - 2024    Contact for me [email protected]