问题描述
原始问题:HTML Original question: Does HTML 最近有人问了一个类似这样的问题,让我想知道. Recently someone asked a question somewhere along these lines, and got me wondering. 以这个为例. 在这个小提琴中,如果您要检查它的宽度(我使用的是来自 chrome 的检查元素),它会显示 In this fiddle, if you were to check its width (I'm using inspect element from chrome), it shows 让我们再添加几个td",我们将看到 Lets add a few more "td"s in, and we shall see that the " 如您所见,现在它是 83px 而不是最初预期的 As you can see, now it's 83px instead of 但是让我们说,我移回较少的 TD (7),并为每个 TD 元素添加更宽的宽度 (500px),结果是 td 的宽度卡在 But let's say, I move back to fewer TD's (7), and I add in a wider width to each TD element (500px), the result is that the width of the td gets stuck at 最后,假设我有一个宽度为 2000px 的表格和 And finally, let's say I have a table of 2000px width, and td of 现在表格宽度覆盖了 TD 宽度,并将 td 的宽度扩展到 Now the table width overrides the TD width, and expands the td's width to 谁能解释这种行为? 附言请注意,在所有情况下,inspect element 工具都告诉我宽度始终与 css 相对应,只是最终结果显示不正确. p.s. Note that in all cases, inspect element tool tells me that the width is always corresponding to the css, it's just the final result not showing correctly. 我非常相信这个问题的答案是这样的: I highly believe the answer to this question is such: 影响TD的宽度的优先级是 The priority of widths that will affect the TD is 表格宽度 Table Width 父元素宽度(如果没有,则为视口) Parent Element Width (and if none, Viewport) 元素(TD)宽度. 因此,如果设置了表格宽度,TD 将始终根据表格的宽度进行调整.但是,如果宽度未设置,主要"宽度将是视口的真实宽度.除非 CSS 代码另有说明,否则这适用.并且只有当 TD 的总宽度小于视口的宽度时,才会考虑元素宽度. Hence if the table width is set, the TD's will ALWAYS adjust to the width of the table. However, if the width is unset, the "main" width will be the true width of the viewport. Unless the CSS code states otherwise, this holds true. And only when the total width of the TD's is smaller than that of the viewport, the elemental width will be taken into account. 编辑 表格宽度将始终覆盖 TD 宽度. Table width will always override TD width. 规定的 TD 宽度只会在超过视口宽度时才会遵循,视口宽度将被优先考虑. Stated TD width will only be followed until it exceeds viewport width, and viewport width will be taken as priority. 这篇关于为什么TD宽度不起作用或没有遵循?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 是否有默认宽度?
<table>
have a default width?100px
,按预期工作.100px
, working as intended.td:100px
"css 被忽略了.td:100px
" css is being ignored.100px
.100px
as originally intended.119px代码>.
119px
.100px
宽度的 td,以及许多 td 元素.http://jsfiddle.net/rqmNY/7/100px
width, and many td elements.http://jsfiddle.net/rqmNY/7/222px
.222px
.推荐答案