I'm trying to create a "fixed-width" table, but it somehow changes the column width whenever the data in column is bigger than rest of them.
For example, following table changes the width on the last number, which is 10.
<table>
<tr>
<td rowspan="3">1</td>
<td>2</td>
<td>3</td>
<td>4</td>
</tr>
<tr>
<td>5</td>
<td rowspan="2" colspan="2">7</td>
</tr>
<tr>
<td>6</td>
</tr>
<tr>
<td>8</td>
<td colspan="2">9</td>
<td>10</td>
</tr>
</table>
Here's my CSS:
table {
border: 1px solid;
width: 400px;
height: 300px;
}
Use style="table-layout:fixed;" , but this will make text or images overlap with other columns in case it exceed the width. Make sure not to place long text phrases without spaces.
To set the table width in HTML, use the style attribute. The style attribute specifies an inline style for an element. The attribute is used with the HTML <table> tag, with the CSS property width.
Turn off AutoFit Select your table. On the Layout tab, in the Cell Size group, click AutoFit. Click Fixed Column Width.
There are 2 algorithms for tables in CSS, triggered by the property table-layout
:
table-layout:
fixed
will adapt cell widths to what the author (you) want, as far as possibletable-layout:auto
(default value) will adapt cell widths to their content.CSS
table {
table-layout: fixed;
width: 400px;
height: 300px;
border: 1px solid;
}
Here's a fiddle: http://jsfiddle.net/tk4J8/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With