gpt4 book ai didi

html - CSS:父元素的 margin-top 不影响子元素的 margin-top

转载 作者:太空宇宙 更新时间:2023-11-04 11:23:59 25 4
gpt4 key购买 nike

简单到我无法理解。看下面的代码;在我对盒子模型的理解中,#content 上的 60px 边距应该将整个 .main div 向下推,而 .main div 的边距应该从页面下方 60px 开始,但实际上 .main 边距与 #content 边距重叠(here's a codepen)

<head>
<style>
#content{
margin-top:60px;
}

.main{
margin-top:20px;
}
</style>
</head>
<body>
<section id="content">
<div class="main">
<h1>Here's some content</h1>
</div>
</section>
</body>

为什么会这样?

编辑:有哪些建议的解决方案?请注意,将 overflow:hidden 添加到父元素是一种解决方案,但这不是一个合适的修复方法;如果我在 .main 中放置一个 h1 并尝试在其上放置一个 top-margin,同样的问题会发生 - 我不想应用 溢出:隐藏一切!

最佳答案

这是因为利润率下降,您可以阅读 here .

关于html - CSS:父元素的 margin-top 不影响子元素的 margin-top,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32547363/

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