Home >Web Front-end >CSS Tutorial >How can I Set Max-Width for Table Cells using Percentages in HTML?

How can I Set Max-Width for Table Cells using Percentages in HTML?

Mary-Kate Olsen
Mary-Kate OlsenOriginal
2024-11-13 09:39:02723browse

How can I Set Max-Width for Table Cells using Percentages in HTML?

Setting Max-Width of Table Cells Using Percentages

In HTML tables, setting the max-width property of table cells using percentages can sometimes prove challenging. Let's explore how to achieve this:

<br><table><br>  <tr></p>
<pre class="brush:php;toolbar:false"><td>Test</td>
<td>A long string blah blah blah</td>



The code above may not produce the desired effect because of the limitations of the CSS rules. To overcome this, we employ the lesser-known table-layout property:

<br>table {<br>  width: 100%;<br>  table-layout: fixed;<br>}<br>

By setting table-layout to fixed, the browser evenly distributes the remaining width among the table cells, allowing you to set max-width percentages as desired.

Check out the updated fiddle here: http://jsfiddle.net/Fm5bM/4/ to witness the implementation in action.

The above is the detailed content of How can I Set Max-Width for Table Cells using Percentages in HTML?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn