Cipater2 Posted June 2, 2009 Share Posted June 2, 2009 Just a quick question about semantics here regarding the <th> tag...In my page I have a couple of 2-column tables. I want to have all the entries in the first column of each table to be bold, and with a colored background, and I'm currently doing this by assigning a class to each type of cell and assigning styles in my stylesheet. My HTML basically looks like this: <table><tr><td class="msmnt_name">A MEASUREMENT</td><td class="msmnt_value">A Value</td></tr><tr><td class="msmnt_name">ANOTHER MEASUREMENT</td><td class="msmnt_value">Another Value</td></tr></table> The question is: can I use <th> and <td> tags like in the below example and still be semantically correct? An end result might look like the following: <table><tr><th>WAIST</th><td>30 inches</td></tr><tr><th>INSEAM</th><td>32 inches</td></tr><tr><th>RISE</th><td>4 inches</td></tr></table> I'm not sure if this is still semantically correct because the headers span the first column of the table, rather than spanning the first row as I've seen in every example of the <th> tag...Thanks in advance! Link to comment Share on other sites More sharing options...
jlhaslip Posted June 2, 2009 Share Posted June 2, 2009 Looks good to me. <TABLE border="1" summary="This table gives some statistics about fruit flies: average height and weight, and percentage with red eyes (for both males and females)."><CAPTION><EM>A test table with merged cells</EM></CAPTION><TR><TH rowspan="2"><TH colspan="2">Average <TH rowspan="2">Red<BR>eyes<TR><TH>height<TH>weight<TR><TH>Males<TD>1.9<TD>0.003<TD>40%<TR><TH>Females<TD>1.7<TD>0.002<TD>43%</TABLE> from : http://www.w3.org/TR/html401/struct/tables.html#h-11.1 Link to comment Share on other sites More sharing options...
Cipater2 Posted June 2, 2009 Author Share Posted June 2, 2009 Awesome - thanks for the info and the link & example! Also, you inadvertently gave me another detail I wasn't aware of - that the end tags for <tr>, <th>, and <td> aren't required. Link to comment Share on other sites More sharing options...
jlhaslip Posted June 2, 2009 Share Posted June 2, 2009 Not required, but a good idea to include them. Good programming. Also, I'm not certain if the lack of end tags will work in xHtml, if you are using that. Link to comment Share on other sites More sharing options...
Synook Posted June 3, 2009 Share Posted June 3, 2009 You always need to close tags in XHTML. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.