Free computer Tutorials

HOME Stay at Home and Learn

Web Design Tutorials

 
Computer Tutorials List

 

 

 

 

How to Align Contents in Table Cells

 

We can align the contents in a cell, so they look more presentable. To align a cells contents, the ALIGN attribute is used in the TD part of the tag. To centre align our headings, the code would be this:

<TR Height = 50 width = 100>
<TD COLSPAN = 2 ALIGN = Center> Home Team </TD>
<TD COLSPAN = 2 ALIGN = Center> Away Team </TD>
</TR>

Again, note the American spelling of centre - "ER" not "RE". You can add a splash of bold to the text in the cell by highlighting the text and clicking on Format > Bold.

As you can see, the centring has made the table look a lot better. There are a lot more alignment options for cell contents than CENTER. The three basic horizontal alignment options are: LEFT, CENTER and RIGHT.

<TD ALIGN = Left>
<TD ALIGN = Center>
<TD ALIGN = Right>

If you want, you can use vertical alignment instead of horizontal. You use the VALIGN tag for vertical alignment. The positions for vertical alignment are: TOP, MIDDLE and BOTTOM.

<TD VALIGN = Top>
<TD VALIGN = Middle>
<TD VALIGN = Bottom>

You can combine horizontal and vertical alignment to give nine positions in all:

<TD VALIGN = Top Align = Left>
<TD VALIGN = Top Align = Center>
<TD VALIGN = Top Align = Right>
<TD VALIGN = Middle Align = Left>
<TD VALIGN = Middle Align = Center>
<TD VALIGN = Middle Align = Right>
<TD VALIGN = Bottom Align = Left>
<TD VALIGN = Bottom Align = Center>
<TD VALIGN = Bottom Align = Right>

In a browser, here's what a table of all nine positions would do to text:

Table Alignment Positions

You can use your HTML Editor to Align the football scores in your table so that they are all in the centre of the cells. Here's how:

  • Click after the "D" of a <TD> tag
  • Type a space
  • From the menu bar, click Format > Table Attributes
  • The Add Table Attributes dialogue box appears once again
  • This time, click the box next to "Set Alignment". The alignment options appear:

Table Alignment

  • The defaults for the ALIGN and VALIGN options are set to None
  • Select an alignment option from the choices and click OK
  • The code is added to your TD tag:

<TD ALIGN = Center VALIGN = Middle>2</TD>

 

In the next part, you'll see how to change the colour of a table cell.

 

<-- Back One Page Move on to the Next Part -->

<--Back to the Web Design Contents Page

View all our Home Study Computer Courses