gpt4 book ai didi

css - 如何将 "clear"设为相对位置?

转载 作者:行者123 更新时间:2023-11-28 09:19:02 25 4
gpt4 key购买 nike

我想到达 body 的 left: 0 但我在相对位置内。有没有办法在不更改容器类的情况下做到这一点?

我正在寻找类似clear: both 的 float 对象。

html:

<div class="container">
<div class="absolute">Content</div>
</div>

风格:

.container {
position: relative;
left: 100px; /*or any other value*/
}

.absolute {
position: absolute;
left: 0;
}

最佳答案

您要求的内容违反了相对包含 block 中绝对定位元素的预期用途。 CSS2 spec说:

Although the parent outer box is not actually offset, setting its 'position' property to 'relative' means that its box may serve as the containing block for positioned descendants.

做你所要求的任何方式都是黑客,你应该重新考虑(a)为什么你需要层次结构,或者(b)为什么你需要包含 block 相对定位.

关于css - 如何将 "clear"设为相对位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18089070/

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