Skip to content Skip to sidebar Skip to footer

How To Semantically Code An Html Nested Table That Aligns (and Associates) With Its Parent Table's Headers

Edit: The selected answer contains a link to the working fiddle I was able to compose without the use of a nested table. I want to semantically code a table in HTML with a layout

Solution 1:

Without the images it's a bit hard to say, but I think a better solution than nested tables would be to simply use the colspan and rowspan attributes.

Edit: Seeing the images I'd say you can most definitely achieve that using rowspan (and colspan the way you're using it already).

Also, you don't need to set the scope attribute if it's "col". It defaults to "col".

Edit: As Marat Tanalin points out the scope attribute's default value is actually auto which "makes the header cell apply to a set of cells selected based on context". And which in my experience acts exactly the same as setting it to "col" (for screenreaders).

Edit: Here are two great articles on marking up advanced tables: http://www.456bereastreet.com/archive/200910/use_the_th_element_to_specify_row_and_column_headers_in_data_tables/ & http://www.456bereastreet.com/archive/200410/bring_on_the_tables/

Edit: Here is the fiddle exhibiting desired behavior (visually at least) and the source code of that fiddle follows:

<tableborder="1"><thead><tr><th>Status</th><th>Type of Loss Dollar</th><th>Reserve Amount</th><th>Paid Amount</th><th>Total This Loss</th></tr></thead><tbody><tr><tdrowspan="3">Open</td><td>Medical</td><td><inputtype="text" /></td><td><inputtype="text" /></td><tdrowspan="3">TOTAL</td></tr><tr><td>Indemnity</td><td><inputtype="text" /></td><td><inputtype="text" /></td></tr><tr><td>Expense</td><td><inputtype="text" /></td><td><inputtype="text" /></td></tr></tbody></table>

Solution 2:

yep, as all the peeps above suggested, it's all about the rowspan.

here's a re-write of your code:

<table><thead><tr><th>Type of Loss Dollar</th><th>Reserve Amount</th><th>Paid Amount</th><th>Total This Loss</th><th>Last Heading</th></tr></thead><tbody><tr><tdrowspan="3"></td><td>Medical</td><td><inputtype="text" /></td><td><inputtype="text" /></td><tdrowspan="3">TOTAL</td></tr><tr><td>Indemnity</td><td><inputtype="text" /></td><td><inputtype="text" /></td></tr><tr><td>Expense</td><td><inputtype="text" /></td><td><inputtype="text" /></td></tr></tbody></table>

Post a Comment for "How To Semantically Code An Html Nested Table That Aligns (and Associates) With Its Parent Table's Headers"