如何使用百分比设置表单元格的最大宽度? [英] How can I set the max-width of a table cell using percentages?

查看:383
本文介绍了如何使用百分比设置表单元格的最大宽度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<table>
<tr>
<td>Test</td>
<td>A long string blah blah blah</td>
</tr>
</table>

<style>
td{max-width:67%;}
</style>

上述操作不起作用。如何使用百分比设置表格单元格的最大宽度?

The above does not work. How can I set the max-width of a table cell using percentages?

推荐答案

根据 CSS 2.1规范中最大宽度的定义,min-width和max的影响对表,内联表,表单元格,表列和列组的宽度未定义。因此,您不能在td元素上直接设置max-width。

According to the definition of max-width in the CSS 2.1 spec, "the effect of 'min-width' and 'max-width' on tables, inline tables, table cells, table columns, and column groups is undefined." So you cannot directly set max-width on a td element.

如果你只想让第二列占据最多67%,那么你可以设置宽度(这是有效的最小宽度,表格单元格)到33%,例如在示例中

If you just want the second column to take up at most 67%, then you can set the width (which is in effect minimum width, for table cells) to 33%, e.g. in the example case

td:first-child { width: 33% ;}

设置这两个列不会很好,因为它倾向于使浏览器给予列等宽。

Setting that for both columns won’t work that well, since it tends to make browsers give the columns equal width.

这篇关于如何使用百分比设置表单元格的最大宽度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆