gpt4 book ai didi

html - 溢出隐藏导致子元素出现在自己的行

转载 作者:太空宇宙 更新时间:2023-11-04 09:11:43 28 4
gpt4 key购买 nike

.container 中的overflow: hidden 导致p 标记落到它自己的行上而不是环绕。这是为什么?

.container {
background-color: green;
overflow: hidden;
}

.floated {
float: left;
background-color: cyan;
}
p {
background-color: pink;
}
<div class='container'>
<div class='floated'>
Floated Div
</div>
<p>Some textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome textSome text</p>
</div>

最佳答案

您看到的额外间距来自段落边距及其处理方式。

overflow: hidden; 添加到您正在创建 block 格式化上下文的容器时。段落元素的边距将包含在 .container 中。

https://developer.mozilla.org/en-US/docs/Web/Guide/CSS/Block_formatting_context

要使段落与 float 元素对齐,请移除段落元素的上边距:

p {
background-color: pink;
margin-top: 0;
}

关于html - 溢出隐藏导致子元素出现在自己的行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42080099/

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