Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

max-width 50% for td

Tags:

html

css

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.

like image 205
Michael Law Avatar asked Jan 21 '13 05:01

Michael Law


People also ask

Can we give width to TD?

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.

How is td width defined?

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.

How do you make all TD widths the same?

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.

What is width max content?

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.

What is the max-width in CSS?

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 .


1 Answers

Add table-layout:fixed;. Change your CSS on the table to:

table{
    width:100%;
    table-layout:fixed;
}

jsFiddle example

like image 141
j08691 Avatar answered Oct 05 '22 11:10

j08691