Hello! I have two tables that are on the same line and if the size of the browser is contracted enough, the right table moves down to the next line, which is what I want. Where I'm stuck is: how do you center these two tables? If both tables are on the same line, there should be roughly 33% space on both sides. And if the second table is on the next line, the two tables should be right in the middle of the page. Here is my code:
How do I fix this?Code:<html> <head> <style type="text/css"> #outerdiv { border: 1px solid blue; } .t { border: 1px solid red; margin: 1em; float: left; } table { border: 1px solid black; border-collapse: collapse; margin: 1em; } table tr td, table tr th { border: 1px solid black; border-collapse: collapse; } .left { text-align: left; } .right { text-align: right; } .clearit { clear: left; } </style> </head> <body> <p>Two tables, side by side, centered together within the page. But if the page is not wide enough, the second table will move on to the next line, and will be centered there instead.</p> <div id="outerdiv"> <div class="t"> <table> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td class="left">January</td> <td class="right">$100</td> </tr> </table> </div> <div class="t"> <table> <tr> <th>Month</th> <th>Savings</th> </tr> <tr> <td class="left">February</td> <td class="right">$200</td> </tr> </table> </div> <div class="clearit">End report</div> </div> </body> </html>


Reply With Quote



Bookmarks