HTML
<table>
<tr>
<td>td1td1td1td1 td1td1td1td1td1td1td1td1td1td1td1</td>
<td>td2</td>
</tr>
</table>
CSS
td{
border:black thin solid;
max-width:50%;
}
table{
width:100%
}
I want to set the max width of the td
to 50%
, but it isn’t working for me ...
Hope someone could help on this.
Please view the output on: http://jsfiddle.net/38bf2/
P.S.
I already try to view the result via Chrome and Firefox.
Using width attribute: The <td> tag has width attribute to control the width of a particular column. By assigning a numeric value to this attribute between 0 to 100 in terms of percentage(or you can use pixel format). We can restrict the column width up to that much percentage of the table's total width.
The HTML <td> width Attribute is used to specify the width of a table cell. If width attribute is not set then it takes default width according to content. Attribute Values: pixels: It sets the width of table in terms of pixels.
Using table-layout: fixed as a property for table and width: calc(100%/3); for td (assuming there are 3 td 's). With these two properties set, the table cells will be equal in size.
The max-content sizing keyword represents the intrinsic maximum width or height of the content. For text content this means that the content will not wrap at all even if it causes overflows.
The max-width CSS property sets the maximum width of an element. It prevents the used value of the width property from becoming larger than the value specified by max-width .
Add table-layout:fixed;
. Change your CSS on the table to:
table{
width:100%;
table-layout:fixed;
}
jsFiddle example
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