Html 如何控制表格单元格的最小宽度?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4116305/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:09:06  来源:igfitidea点击:

How do you control the minimum width of a table cell?

htmlcsshtml-table

提问by Darryl Hein

I have a need in a variety of cases to ensure a table cells don't shrink past a certain width. To accomplish this I've tried a number of options with varying results. Some of the options I've tried:

我在各种情况下都需要确保表格单元格不会缩小超过一定的宽度。为了实现这一点,我尝试了许多具有不同结果的选项。我尝试过的一些选项:

  • width on the td: works alright, but some browsers ignore it and it's not valid in HTML5
  • CSS width inside style=""or stylesheet: ignored by some browsers
  • image with width=X and height=1: causes the content of the td to be push up or down (by more than 1px).
  • div with width=X and height=1 and float:left: this seems to work the best at the moment, although it does push the content up or down slightly
  • td 上的宽度: 工作正常,但有些浏览器会忽略它并且它在 HTML5 中无效
  • CSS 宽度style=""或样式表:被某些浏览器忽略
  • width=X 和 height=1 的图像:导致 td 的内容被向上或向下推(超过 1px)。
  • width=X 和 height=1 和 float:left 的 div:这似乎目前效果最好,尽管它确实将内容稍微向上或向下推

Any other ideas?

还有其他想法吗?

I need to it work in anything, including IE6 :( but if there are solutions that don't work in IE6, but everything else, that'd be a start anyway :)

我需要它在任何东西上都能工作,包括 IE6 :( 但如果有在 IE6 中不起作用的解决方案,但其他所有东西,那都是一个开始 :)

回答by Brandon Durham

You can't reliably control the width of a table cell. It's best to wrap the contents in a DIV (or any other block level elements) and target that element.

您无法可靠地控制表格单元格的宽度。最好将内容包装在 DIV(或任何其他块级元素)中并以该元素为目标。

回答by Darryl Hein

min-widthwill correctly control the minimum -- inbrowsers that support it correctly. Often times widthcan work like min-widthin IE6-ish nonsense. YMMV.

min-width将正确控制最小值——正确支持它的浏览器中。很多时候width可以像min-width在 IE6-ish 废话中一样工作。天啊。

回答by Scott Baker

Look at min-width. Not IE6 compatible, but it'll rock in most other browsers.

看看最小宽度。不兼容 IE6,但它会在大多数其他浏览器中运行。