5 Replies - 1368 Views - Last Post: 20 September 2006 - 10:21 AM

#1 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 817
  • Joined: 22-November 04

What's wrong with this table?

Posted 18 September 2006 - 02:40 PM

What is wrong with the display of this table:

<?xml version="1.0"?>
<!DOCTYPE html PUBLIC
		"-//W3C//DTD XHTML 1.0 Transitional//EN"
		"http://www.w3.org/TR/xhtml/11/DTD/xhtml1-
		 transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

	<head>
		<title>Assignment 2 Jonathan Cox</title>

					<style type="text/css">
					body{background-color:gray; text-align:center;}
					  h2{color:blue;}
				   table{text:center;}
					  li{text-align:left;}
					</style>
	</head>

	<body>

				
					<h2>My Favorite Music and Movies</h2>
					
					<center>
					<table border="2" height="500" width="300">
						<td>
							  <th><br /></br>Music<br /><br />
									<ol>
										<br />
										<li>Slayer</li><br />

										<li>Johnny Cash</li><br />
										<li>Liquid Swords</li><br />
										<li>Jimi Hendrix</li><br />
							  </th>
					   

					   
							  <th> Movies <br /><br /><br />
									<ul>

										 <li>Ghost Dog</li><br />
										 <li>Rush</li><br />
										 <li>The Game</li><br />
										 <li>Rush Hour 2</li>
							 </th>
									
					   </td>

					</table>
					</center>		
	</body>





</html>


Is This A Good Question/Topic? 0
  • +

Replies To: What's wrong with this table?

#2 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: What's wrong with this table?

Posted 18 September 2006 - 02:46 PM

you have <td> </td> encaspulateing your <th> in your table

the nesting order shoudl be

table
th
td
/td
/th
/table

or substitute tr with th
Was This Post Helpful? 0
  • +
  • -

#3 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 817
  • Joined: 22-November 04

Re: What's wrong with this table?

Posted 18 September 2006 - 05:33 PM

Ok, I tried replacing th with tr (since I had no tr's like this:

<table border="2" height="500" width="300">
						<td>
							  <tr><br /></br>Music<br /><br />
									<ol>
										<br />
										<li>Slayer</li><br />

										<li>Johnny Cash</li><br />
										<li>Liquid Swords</li><br />
										<li>Jimi Hendrix</li><br />
							  </tr>
					  

					  
									   <tr> Movies <br /><br /><br />
										   <ul>

											  <li>Ghost Dog</li><br />
											  <li>Rush</li><br />
											  <li>The Game</li><br />
											  <li>Rush Hour 2</li>
									   </tr>
							 
									
					   </td>

					</table>
					</center>		


...and I tried to nest the th's better but as you can see it just gets worse and worse. No fault but my own:(
<table border="2" height="500" width="300">
						<td>
							  <th><br /></br>Music<br /><br />
									<ol>
										<br />
										<li>Slayer</li><br />

										<li>Johnny Cash</li><br />
										<li>Liquid Swords</li><br />
										<li>Jimi Hendrix</li><br />
							  
					  

					  
										Movies <br /><br /><br />
										   <ul>

											  <li>Ghost Dog</li><br />
											  <li>Rush</li><br />
											  <li>The Game</li><br />
											  <li>Rush Hour 2</li>
									   </th>
							 
									
					   </td>

					</table>

Was This Post Helpful? 0
  • +
  • -

#4 Nova Dragoon  Icon User is offline

  • The Innocent Shall Suffer, Big Time
  • member icon

Reputation: 36
  • View blog
  • Posts: 6,169
  • Joined: 16-August 01

Re: What's wrong with this table?

Posted 18 September 2006 - 08:29 PM

you still have the td's outside the tr/ths
<table border="2" height="500" width="300">
						<td>


those cant go there, td needs to be inside tr or th only
Was This Post Helpful? 0
  • +
  • -

#5 Arbitrator  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 51
  • View blog
  • Posts: 530
  • Joined: 26-January 05

Re: What's wrong with this table?

Posted 19 September 2006 - 12:40 PM

Some people apparently don't know what a table header cell element is. The "th" stands for "table header cell" and is identical in functionality to a table data cell (td) element except that it has certain extra styles associated with it; in Mozilla, for example, the contents of a table header cell element are centered and in bold by default. The nesting order of the relevant elements is:

<table>
  <tr>
(table row)
    <th></th> or <td></td> (table header or table data cells)
  </tr>
</table>


A table row element must be a direct child of a table. Table header and table data cell elements must be the direct children of a table row element. All table information must go inside one of the two table cell elements. Of course, tables are even more complicated than that when you consider the other elements such as thead (table header), tfoot (table footer), tbody (table body), caption, colgroup (column group), and col (column), but I won't get into that.

Just so you (Israel) know, that code has numerous other problems associated with it:
1. The border, height, and width attributes are deprecated (old, obsolete) on tables in favor of equivalent and identically named CSS properties; note that the border attribute is deprecated for use on everything, not just tables. Table data (td) and table header (th) cell elements MUST BE contained within table row (tr) elements. Likewise, table row elements CAN ONLY contain table data or table header cell elements; they cannot contain text or other code.

2. Don't close a tag twice (<br /></br>); pick one way (<br/>) or the other (<br></br>); note that the second method is more likely to cause backward compatibility issues. And, no, the space before the closing slash isn't required; that's just for backward compatibility for browsers that can't parse XHTML as HTML correctly.

3. The ordered list (ol) element element CANNOT contain markup or content anywhere except inside its list item (li) element tags. That means that all of those line-break elements you stuck in there are invalid. In addition, you need to insert </ol> to close the ordered list since XHTML requires that ALL elements be closed; that's exactly the reason you've been putting closing slashes in your line-break elements. The same goes for the unordered list (ul) element; it needs a closing tag.

4. Also keep in mind that you do not need to be using both lists and tables to display the same data. Simply pick one. If you choose to go with tables, you can remove the parent list elements (ol and ul) and replace the list item elements with table cell elements. Otherwise, you can remove the tables and allow the lists to stand on their own.

5. The center element is deprecated in favor of CSS and shouldn't be used. Use the CSS declarations margin-right: auto; margin-left: auto; (or margin: 0 auto, for short) to center that table. Note that this won't work in Internet Explorer while that browser is in quirks mode; removing the optional XML declaration (<?xml version="1.0"?>) from your markup should put IE back into standards-compliance mode. The text-align property is for centering text and shouldn't allow you to center the table, but IE incorrectly allows you to do this anyway. And just for reference, the bug where the XML declaration triggers quirks mode is fixed in Internet Explorer 7.

6. The text property doesn't exist (table{text:center;}). Did you mean text-align?

7. You should correct the URI referenced in your DTD as http://www.w3.org/TR...ransitional.dtd is incorrect. It should be http://www.w3.org/TR...ransitional.dtd. If you try visiting each URI, you'll see that this is the case. Preferably, you should be using a strict DTD though.

Happy coding! ~Arbitrator

This post has been edited by Arbitrator: 20 September 2006 - 11:12 AM

Was This Post Helpful? 0
  • +
  • -

#6 Israel  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 7
  • View blog
  • Posts: 817
  • Joined: 22-November 04

Re: What's wrong with this table?

Posted 20 September 2006 - 10:21 AM

Quote

Just so you (Israel) know


Way to call a guy out... :huh: Yeah, I won't use lists inside tables but that's what my teacher wanted. The DOC type was the one he instructed us to use and I would rather use xhtml-strict but we're doing transitional in class. Some of those errors were typos and some of it was just plain my bad. But I'm trying to learn xhtml the right way and re-learn old html stuff I've forgotten. Thanks for the lesson though.

This post has been edited by Israel: 22 September 2006 - 11:37 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1