拥有“display: table-cell”元素而不是“display: table-row”元素是有效的构造吗?

时间:2022-11-20 16:21:47

In a sample web application I have to work on, I noticed that some elements had a display: table-cell style but their parent don't have display: table-row.

在我必须处理的一个示例web应用程序中,我注意到有些元素有一个display: table-cell样式,但是它们的父元素没有display: table-row。

To me thats seems wrong, but I'm not sure at all.

对我来说这似乎是不对的,但我一点也不确定。

Hence this question: Is this a valid construct ? What problems can it cause, if any ?

因此,这个问题是:这是一个有效的构造吗?如果有的话,它会造成什么问题呢?

Thank you.

谢谢你!

Here is an example of what I meant:

这里有一个例子说明我的意思:

<div style="display: block">
  <div style="display:table-cell">
    <p>Some content</p>
  </div>
</div>

1 个解决方案

#1


3  

I'm kind of parroting Faust who was kind enough to find the specs (but seems to have now removed his answer)...

我有点像《浮士德》(Faust),他很好心地找到了眼镜(但现在看来他的答案被删除了)……

Yes, it is (probably) valid.

是的,它(可能)是有效的。

Document languages other than HTML may not contain all the elements in the CSS 2.1 table model. In these cases, the "missing" elements must be assumed in order for the table model to work. Any table element will automatically generate necessary anonymous table objects around itself, consisting of at least three nested objects corresponding to a 'table'/'inline-table' element, a 'table-row' element, and a 'table-cell' element.

除了HTML之外的文档语言可能不包含CSS 2.1表模型中的所有元素。在这些情况下,必须假定“缺失”元素,以便表模型能够工作。任何表元素都会自动生成必要的匿名表对象,包括至少三个与“表”/“行”元素、“表行”元素和“表单元”元素对应的嵌套对象。

From 17.2.1 Anonymous table objects, http://www.w3.org/Style/css2-updates/css2/tables.html#anonymous-boxes

从17.2.1匿名表对象,http://www.w3.org/Style/css2-updates/css2/tables.html#匿名框

This could be read as anonymous boxes will be created in non-HTML languages that don't have the right construct but I would assume that it will generate anonymous table objects in HTML as well.

这可以被理解为匿名框将在没有正确构造的非HTML语言中创建,但我假设它也将在HTML中生成匿名表对象。

#1


3  

I'm kind of parroting Faust who was kind enough to find the specs (but seems to have now removed his answer)...

我有点像《浮士德》(Faust),他很好心地找到了眼镜(但现在看来他的答案被删除了)……

Yes, it is (probably) valid.

是的,它(可能)是有效的。

Document languages other than HTML may not contain all the elements in the CSS 2.1 table model. In these cases, the "missing" elements must be assumed in order for the table model to work. Any table element will automatically generate necessary anonymous table objects around itself, consisting of at least three nested objects corresponding to a 'table'/'inline-table' element, a 'table-row' element, and a 'table-cell' element.

除了HTML之外的文档语言可能不包含CSS 2.1表模型中的所有元素。在这些情况下,必须假定“缺失”元素,以便表模型能够工作。任何表元素都会自动生成必要的匿名表对象,包括至少三个与“表”/“行”元素、“表行”元素和“表单元”元素对应的嵌套对象。

From 17.2.1 Anonymous table objects, http://www.w3.org/Style/css2-updates/css2/tables.html#anonymous-boxes

从17.2.1匿名表对象,http://www.w3.org/Style/css2-updates/css2/tables.html#匿名框

This could be read as anonymous boxes will be created in non-HTML languages that don't have the right construct but I would assume that it will generate anonymous table objects in HTML as well.

这可以被理解为匿名框将在没有正确构造的非HTML语言中创建,但我假设它也将在HTML中生成匿名表对象。