让单元格保持 10% 宽

发布于 2024-11-02 20:24:29 字数 113 浏览 5 评论 0原文

我有一个 10% 宽的单元格,里面有几个单词。当您缩小窗口大小时,大小会不断变小,直到与内部文本的长度匹配,然后停止缩小。我希望它保持在 10% 的宽度。我该怎么做?

抱歉,不能选择使用 div。

I have a cell that is 10% wide with a couple words in it. When you shrink the window size, the size keeps getting smaller until it matches the length of the text inside and then it stops shrinking. I want it to stay at an exact 10% wide. How do I do this?

Sorry, working with divs is not an option.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤寂小茶 2024-11-09 20:24:29

这可能会起作用:

#your_table {
  table-layout: fixed;
}

表格(应该由浏览器来实现)有两种类型的布局:

  1. table-layout:fixed:这是“愚蠢”的表格布局。该表不关心其内容,只是随意调整大小。
  2. table-layout: auto:这是“智能”表格布局。表关心其内容,并在达到单元格的最小宽度和高度后停止调整单元格大小。这是默认的表行为。

谢谢 W3C:http://www.w3.org/TR /CSS2/tables.html#propdef-table-layout

This might do the trick:

#your_table {
  table-layout: fixed;
}

Tables can (should, as it's up to browsers to implement this) have two types of layouts:

  1. table-layout: fixed: This is the "stupid" table layout. The table doesn't care about its contents and just resizes carelessly.
  2. table-layout: auto: This is the "smart" table layout. The table cares about it's contents and stops resizing cells once the minimum width and height of a cell is reached. This is default table behavior.

Thank you W3C: http://www.w3.org/TR/CSS2/tables.html#propdef-table-layout

暮凉 2024-11-09 20:24:29

看来您真正想要的是设定宽度。如果您说表格必须为 300px,则可以指定单元格始终为 30px。相对规模是导致问题的原因。

table.myClass{
    width: 300px;
}

table.myClass td.myOtherClass{
    width: 10%;
}

It looks like what you really want is a set width. If you say that the table has to be 300px, you can specify that the cell is always 30px. The relative scale is what's causing the problem.

table.myClass{
    width: 300px;
}

table.myClass td.myOtherClass{
    width: 10%;
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文