gpt4 book ai didi

html - float 元素的包含 block 是什么?

转载 作者:行者123 更新时间:2023-11-28 01:02:14 24 4
gpt4 key购买 nike

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.

我想知道 float 元素的包含 block 是什么,我测试了:

body {
position: relative;
margin: 5px;
padding: 10px;
}

p {
float: left;
position: absolute;
margin: 10px;
}

<body>
<p>hehe</p>
</body>

根据 css2.1 spec ,绝对定位元素的包含 block 是最近的定位 block 容器的填充框。

但是在上面的代码中, float 的元素是 float 到内容框边界的。我很困惑如何找到 float 元素的包含 block 。

最佳答案

你的问题的前提是有缺陷的。绝对定位的元素不能 float , float 不能绝对定位。来自 section 9.7 :

[...] if 'position' has the value 'absolute' or 'fixed', the box is absolutely positioned, the computed value of 'float' is 'none' [...]

因此,您并不是要在此处查找 float 的包含 block 。您正在尝试查找弃用元素的包含 block 。

话虽如此,如果您真的必须知道, float 的包含 block 与我在 my answer to your previous question 中描述的相对定位或非定位元素相同。 ,因为不能弃用 float 。

关于html - float 元素的包含 block 是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41587518/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com