CMS

Content

HTML

Images

Monetizing

Home » HTML

Defining Table Width & Height

Monday, 22 March 2010 · Print This Post Print This Post No Comment

Related Reading

This entry is part 4 of 6 in the series Tables

Next in our free online web design course, we’re going to learn how to define the “width” and “height” of our table. These two attributes can be defined in two ways: either as a fixed length (i.e. width=”360″) or a percentage (i.e. width=”80%”). When you define your width as a percentage, your table will expand or impend depending on the total width/height of your browser window and your screen resolution. Therefore it is much more sound to use a percentage to define the width/height of your tables.

Copy and paste the HTML code below to create a two tables – one with a fixed width (900 pixels) and the other with a percentage width (90%):

<html>
<head>

</head>
<body>

<table border=”1″ width=”900″>
<tr>
<td>
Row 1
</td>
</tr>

<tr>
<td>
Row 2
</td>
</tr>
</table>

<br><br>

<table border=”1″ width=”90%”>
<tr>
<td>
Row 1
</td>
</tr>

<tr>
<td>
Row 2
</td>
</tr>
</table>

</body>
</html>

If you save this HTML code and open it as an HTML page, you’ll get a page with two tables. The first one will remain fixed however you resize your browser window, but the other one will adjust itself to fit the 90% of the total width of the resized window. Note that the “height” attribute acts in the same manner as the “width” attribute.

Defining The Size Of HTML Table Cells

You can also set the width and height of each individual cell by using the “width” and “height” attributes along with the <td> tag:

<html>
<head>

</head>
<body>

<table border=”1″>
<tr>
<td width=”100″ height=”50″>
Column 1
</td>
<td width=”200″>
Column 2
</td>
</tr>
</table>

</body>
</html>

Our output will be:

Column 1 Column 2

Notice that the height of the whole row has been defined by adding a height value to only one of the <td> tags. You do not need to define the “height” attribute in each column – only one will suffice. Same with the “width” attribute and rows.

If you enjoyed this lesson, please link to it :)

We’re through with the “width” and “height” attributes. In the next lesson of our online web design course, we’re going to learn how to “merge” table cells.

Series Navigation«Cellpadding & CellspacingMerging Table Cells»

Bookmark this Post Subscribe to Blog

Popular Tags

Adsense Background Cascading Style Sheets colors Content font Forms GIF Hex Codes HTML Hyperlinking Images IMeye JavaScript JPEG Keyword Research layout Merging meta PNG SEO Sizing spacer Tables text W3C
Leave a Comment

Threaded commenting powered by Spectacu.la code.