I use twitter bootstrap for a responsive design that contains a four-column table. I want the columns of the table to have equal width, so I set td width to 25%.
I would think that the rows of the table inherit their size from the table, and the cells of the table will be one quarter. This seems to work when the width of the device is 768 pixels or more. When the width of the device is smaller, the rows are sized based on the text in the largest cell, unlike the size of the parent table.
I included some code example below, with the background color on different elements, to highlight the error (as can be seen from the horizontal resizing of the window). Errors are highlighted in yellow (where the main color of the table is displayed).
Real-time example: http://pastehtml.com/view/cqrwl31z2.html
I tested in Chrome and Safari.
<!DOCTYPE html> <html> <head> <title>Table Test</title> <link href="http://www.bootstrapcdn.com/twitter-bootstrap/2.2.2/css/bootstrap-combined.min.css" rel="stylesheet" media="screen"> <script type="text/javascript" src="http://www.bootstrapcdn.com/twitter-bootstrap/2.2.2/js/bootstrap.min.js"></script> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <style> td, th { width: 25% !important; } table { background-color: yellow; } tr { background-color: gray; } th { background-color: aqua; } td:nth-child(1) { background-color: red; } td:nth-child(2) { background-color: green; } td:nth-child(3) { background-color: blue; } td:nth-child(4) { background-color: purple; } </style> </head> <body> <div class="container"> <h1>Hello, world!</h1> <div class="row"> <table class="span12"> <thead> <tr> <th>A</th> <th>B</th> <th>C</th> <th>D</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <tr> </tbody> </table> </div> <div class="row"> <table class="span12"> <thead> <tr> <th>Longer Table</th> <th>Headers In</th> <th>This</th> <th>Table</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> <td>3</td> <td>4</td> <tr> </tbody> </table> </div> </div> </body> </html>
source share