Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XHTML Question 1

Status
Not open for further replies.

hjmc

Technical User
Nov 20, 2002
38
GB
I have been musing over why the HEIGHT attribute in a TABLE element is being ignored. I have tracked it down to a DOCTYPE statement.

The code I ended up testing is as follows

<%@ Page Language="VB" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "
<html xmlns=" xml:lang="en">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<table border="2" cellpadding="0" cellspacing="0" style="width: 100%; height: 100%">
<tr>
<td colspan="2" style="height:40%">Testing 1
</td>
</tr>
<tr>
<td style="height:30%">Testing 2
</td>

</tr>
<tr>
<td colspan="2" style="height: 30%">Testing 3
</td>
</tr>
</table>

</form>
</body>
</html>

The above code seems to ignore the 'height' attribute.

However, if I take the DOCTYPE out, I get the 3 rows with the 'height' attribute being obeyed.

Can someone explain this please.

Thanks for your help. You are great people.
 
Your table is 100% of what? Since nothing is defined before the table, all elements have auto height, or as high as the content. Your table has 100% height of the parent container (in this case the form), which is as big as the content. Thus, both elements are just as high as the content.

Without a doctype, this simple truth is avoided and assumes that 100% height in a table refers to the 100% of the viewport. This however is erroneous.

If you want to have your table at 100% height, you need to define 100% height for your html, body and form elements.

___________________________________________________________
[small]Do something about world cancer today: PACT[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top