I managed to obtain this kind of table layout:
fixed - dynamic(50%) - dynamic(50%) - fixed
http://jsfiddle.net/ihtus/ksucU/
But how do I get this kind? fixed - dynamic(30%) - dynamic(70%) - fixed
Here's my CSS:
table {
width:100%;
border-collapse:collapse;
table-layout:fixed;
}
td {
border: 1px solid #333;
}
By using CSS, the styling of HTML elements is easy to modify. To fix the width of td tag the nth-child CSS is used to set the property of specific columns(determined by the value of n) in each row of the table.
Complete HTML/CSS Course 2022 To set the cell width and height, use the CSS style. The height and width attribute of the <td> cell isn't supported in HTML5. Use the CSS property width and height to set the width and height of the cell respectively.
The CSS to make all the columns equal in width is as follows. The table-layout: fixed; rule specifies that the table is to take its dimensions from the <table> element's width and the width of the first row of cells (or the <col> elements, if you have them).
Like this:
<table>
<tr>
<td style="width:200px;">
200px width - content
</td>
<td width="30%">
dynamic width - content
</td>
<td width="70%">
dynamic width - content
</td>
<td style="width:100px;">
100px width - content
</td>
</tr>
</table>
table {
width:100%;
border-collapse:collapse;
table-layout:fixed;
}
td {
border: 1px solid #333;
}
http://jsfiddle.net/7dSpr/
The general approach is the same as the one Monkieboy used, but you should avoid inline styles. ( by that I mean writing style="someting"
) in your html file. You should use classes and CSS instead.
First give the td a class like this <td class="thin-column">text here</td>
,
then in your CSS use that to apply styles: .thin-column:{ width: 30% }
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