浮动元素的包含块是什么?
What's the containing block of floated elements?
In css2.1 spec,上面写着:
A floated box is shifted to the left or right until its outer edge touches the containing block edge or the outer edge of another float.
我想知道浮动元素的包含块是什么,我测试了:
body {
position: relative;
margin: 5px;
padding: 10px;
}
p {
float: left;
position: absolute;
margin: 10px;
}
<body>
<p>hehe</p>
</body>
根据css2.1 spec,绝对定位元素的包含块是最近的定位块容器的填充框。
但是在上面的代码中,浮动的元素是浮动到内容框边界的。我很困惑如何找到浮动元素的包含块。
你的问题前提有问题。绝对定位的元素不能浮动,浮动不能绝对定位。来自 section 9.7:
[...] if 'position' has the value 'absolute' or 'fixed', the box is absolutely positioned, the computed value of 'float' is 'none' [...]
因此,您并不是要在此处查找浮点数的包含块。您正在尝试查找弃权元素的包含块。
话虽如此,如果您真的必须知道,浮点数的包含块与我在 中描述的相对定位或非定位元素相同,因为浮点数不能被放弃。
In css2.1 spec,上面写着:
A floated box is shifted to the left or right until its outer edge touches the containing block edge or the outer edge of another float.
我想知道浮动元素的包含块是什么,我测试了:
body {
position: relative;
margin: 5px;
padding: 10px;
}
p {
float: left;
position: absolute;
margin: 10px;
}
<body>
<p>hehe</p>
</body>
根据css2.1 spec,绝对定位元素的包含块是最近的定位块容器的填充框。
但是在上面的代码中,浮动的元素是浮动到内容框边界的。我很困惑如何找到浮动元素的包含块。
你的问题前提有问题。绝对定位的元素不能浮动,浮动不能绝对定位。来自 section 9.7:
[...] if 'position' has the value 'absolute' or 'fixed', the box is absolutely positioned, the computed value of 'float' is 'none' [...]
因此,您并不是要在此处查找浮点数的包含块。您正在尝试查找弃权元素的包含块。
话虽如此,如果您真的必须知道,浮点数的包含块与我在