I'm trying to create a <table> that doesn't exceed a certain width (let's say 500px), even with borders of any size.
Normally, if I do:
(HTML)
<div>
<table>
<tr>
<td>This is a test.</td>
</tr>
</table>
</div>
(CSS)
div {
width: 500px;
}
table {
width: 100%;
border: 10px solid #000;
}
I'm going to end up with a <table> that is 510px wide, since half of the left and right borders will end up on the outside of the <div>. What I want is a <table> that is 500px wide total (i.e., that doesn't exceed the width of its parent/container). So, the left and right borders would each be 10px wide, set inside the 500px-wide containing <div> - therefore the table's remaining content area would be 480px.
I can easily do this type of thing to a <div> by using the CSS declaration "width: auto." I can fake it with a table by adding an extra <div> around it that uses "width: auto" with the border set on that <div>, not the <table>.
However, I'm hoping that a more elegant solution exists (must be cross-browser). Is there one that I'm not aware of?