【发布时间】:2020-07-03 11:38:13
【问题描述】:
我一直在尝试在顶部放置一些标签:一些 div 的 0px。
我的问题是,当我放置“top: 0px”时,它并没有将 my 放在父 div 的顶部。
我一直在搜索这方面的一些信息,这似乎是一个“Collapsing Margin”问题..
我已经尝试自己修复它,但是如果不保留主要结构(主类居中.. 宽度为 100% 的标题.. 等),我无法修复它
header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 10px 50%;
background-color: grey;
position: fixed;
top: 0px;
width: 100%;
height: 50px;
z-index: 1000;
}
.topzone {
margin-top: 50px;
display: flex;
align-items: center;
justify-content: center;
}
.main {
margin: 0 auto;
display: flex;
align-items: center;
flex-direction: column;
max-width: 950px;
}
.inside-main {
background-color: white;
width: 100%;
height: 375px;
}
.inside-title {
justify-content: center;
text-align: center;
width: 75%;
margin: 0 auto;
}
.inside-content {
display: flex;
flex-wrap: wrap;
justify-content: center;
text-align: center;
width: 75%;
margin: 0 auto;
}
.inside-content div {
position: relative;
width: 30%;
margin: 0px 10px 0px 10px;
}
.inside-content img {
width: 100%;
}
.inside-content div h3 {
position: absolute;
top: 0px;
width: 100%;
}
<header>
<div>
<button id="login">1</button>
<button id="signin">2</button>
</div>
</header>
<div class="topzone">
<h1>TOP ZONE TITLE</h1>
</div>
<div class="main">
<div class="inside-main">
<div class="inside-title">
<h1>INSIDE TITLE ZONE</h1>
</div>
<div class="inside-content">
<div>
<img src="https://etc.usf.edu/clipart/21900/21988/square_21988_md.gif" alt="Just a box">
<h3>Box 1</h3>
</div>
<div>
<img src="https://etc.usf.edu/clipart/21900/21988/square_21988_md.gif" alt="Just a box">
<h3>Box 2</h3>
</div>
<div>
<img src="https://etc.usf.edu/clipart/21900/21988/square_21988_md.gif" alt="Just a box">
<h3>Box 3</h3>
</div>
<div>
<img src="https://etc.usf.edu/clipart/21900/21988/square_21988_md.gif" alt="Just a box">
<h3>Box 4</h3>
</div>
<div>
<img src="https://etc.usf.edu/clipart/21900/21988/square_21988_md.gif" alt="Just a box">
<h3>Box 5</h3>
</div>
<div>
<img src="https://etc.usf.edu/clipart/21900/21988/square_21988_md.gif" alt="Just a box">
<h3>Box 6</h3>
</div>
</div>
</div>
在此示例中,Box1、Box2 等。应与每个框的顶行高度相同。
谢谢
【问题讨论】:
-
对我来说没问题...你能发布问题的屏幕截图吗?
-
这里也一样。究竟是什么问题?
-
对我来说就是这样。您能否发布您看到的错误/损坏版本的屏幕截图?
-
嗯,在截图中,你可以看到“Box 1”和“Box 2”,不在Div的TOP(基本上,如果我使用top:0px,红色条包含两个
应该几乎在顶框线的相同高度)
标签: html css layout position margin