A Little Trick to Span a Row Over the Whole HTML Table

If you want to span a row over multiple columns in an HTML table, you can use the colspan attribute on the td element. You may know the approach in which you specify the number of columns you want to span. A much simpler way to span all columns is to use 100%:

Col 1 Col 2 Col 3
     
     
footer

You get the same effect as when you specify the number of columns, but this way you do not need to count the columns. This is especially helpful when you create tables dynamically in code. This little trick is supported down to IE 7 and works with all modern browser.

 

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.