Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialJustin Stephens
3,375 PointsHow come my colspan is not working?
<table border="1"> <thead> <tr> <th>Author(s)</th> <th>Book Title</th> </tr> </thead> <tfoot> <tr> <td colspan="2"align="center"> thanks </td> </tr> </tfoot> <tbody> <tr> <td>John Steinbeck</td> <td>The Grapes of Wrath</td> </tr> </tbody> </table>
2 Answers
Alessandra Vaughn
13,915 PointsI find the easiest way to troubleshoot with tables is to add a border.
<table border="1">
<tr>
<td>something</td>
<td>here</td>
</tr>
</table>
Blake Hutchinson
21,695 PointsA COLSPAN is an attribute for the TH and TD tags, both part of the overall TABLE tag. The tricky thing about tables is that if opening and closing tags are not matching, then the table won't look like it should. Also, make sure number of TD tags match (with the exception of those using COLSPAN and/or ROWSPAN attributes) from beginning to end. If you have any empty table cells, then putting (non-breaking space) in them will keep the cells looking consistent.
Here's some example code which you can save as an HTML file and preview in a browser. Just remember it's not valid HTML5.
<html>
<head>
<title>Example Table</title>
<style>
table, th, td { border: 1px solid gray; }
</style>
</head>
<body>
<table border="1" width="100%" cellspacing="0">
<th>1</th><th>2</th><th>3</th>
<!-- 1 td tag as colspan = 3 -->
<tr bgcolor="blue"><td colspan="3"> </tr>
<!-- 2 td tags as colspan = 2 -->
<tr><td colspan="2" bgcolor="red"> </td>
<td rowspan="2" bgcolor="yellow"> </td></tr>
<!-- 2 td tags as rowspan from above = 2 -->
<tr><td bgcolor="green"> </td><td bgcolor="lime"> </td></tr>
<!-- 3 td tags as no colspan on line or any intercepted rowspan from above -->
<tr><td bgcolor="teal"> </td><td bgcolor="orange"> </td>
<td bgcolor="black"> </td></tr>
</table>
</body>
</html>
Jeff Busch
19,287 PointsJeff Busch
19,287 PointsCan we see your code?