gpt4 book ai didi

html - 清除 :both affected by outside floated elements?

转载 作者:行者123 更新时间:2023-11-28 03:27:52 24 4
gpt4 key购买 nike

我有 2 个 div。红色是 float:left (width:100px)

绿色的 div 是 margin-left:101px( float )

enter image description here

green div 中,我添加了一个带有 2 个 float 元素的 div :

enter image description here

所以结果是:

enter image description here

一切正常。

但是如果我在此处添加一个带有 clear:bothdiv :

enter image description here

它被拉伸(stretch)超出红色div的底部:

enter image description here

我的问题是为什么是这样?

我知道 clear:both 应该不允许在两个正确的位置但在同一个容器下允许任何 float 元素! !!

我们在这里谈论的是绿色 div 容器。为什么 clear:both 也考虑红色 div ?这超出了他的范围!

有什么帮助吗?

(我正在寻找原因。另外 - 我如何更改 clear:both 以按需要工作)

( http://jsbin.com/oQEXANOK/3/edit )

附:

红色和绿色 div 的 css 是强制性的。这就是网站目前的构建方式。

编辑:

我发现如果我把 float:left 放在这个 :

enter image description here

它的行为应该是这样的:

enter image description here

(这里发生了什么……?)

最佳答案

最好将 margin-left 替换为 float:left

关于html - 清除 :both affected by outside floated elements?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20041719/

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