如何在 HTML 或 CSS 中指定表格列应具有最小宽度
如何在 HTML 或 CSS 中指定表格列相对于列内容应具有最小宽度。
我尝试过 max-width 但不起作用
.p
{
max-width:10px;
background-color:yellow;
}
<table> ...
<td nowrap class="p">text</td>
...<table>
How do I specify in HTML or CSS that a table column should have the minimum width with respect to column content.
I have tried max-width but doesn't work
.p
{
max-width:10px;
background-color:yellow;
}
<table> ...
<td nowrap class="p">text</td>
...<table>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您是否尝试过 min-width ?你在 CSS 中使用了 max-width 。
did you try min-width instead? you used max-width in your CSS.
按如下方式更改代码:
以下是该代码的实际操作示例。
Change the code as follows:
Here's an example of that code in action.
我看到你发布这个问题已经有一段时间了,但我自己也遇到了同样的问题。
似乎有效的方法是为列提供一个小于最小值的显式宽度,例如
浏览器尝试使用此宽度,发现它小于最小宽度,因此用最小宽度覆盖它。这是有记录的行为,它在 IE、Firefox 和 Chrome 中对我有用。
我更喜欢更干净的东西,比如“width=minimum”,但我想如果它有效的话你还能要求什么呢。
I see it's a while since you posted this question, but I just ran into the same issue myself.
What appears to work is to give the column an explicit width that is smaller than the minimum, like say
The browser attempts to use this width, discovers that it is less than the minimum width, and so overrides it with the minimum width. This is documented behavior and it worked for me in IE, Firefox, and Chrome.
I'd prefer something cleaner, like "width=minimum", but I guess if it works what more can you ask for.