百分比设置正确,但.mycompany不是根据布局设置的位置。从顶部边缘开始,它必须在 59px 的距离处,整个高度.mycompany为 790px。但!使用时,top一切正常
css
* {
margin: 0;
padding: 0;
}
.general {
height: 6200px;
}
header {
height: 790px;
background-color: black;
}
.mycompany {
position: relative;
margin-left: 12.1%;
margin-top: 7.2%;
color: white;
font-size: 1.5em;
display: inline-block;
text-transform: uppercase;
}
HTML
<div class="general">
<header>
<span class="mycompany">mycompany</span>
</header>
</div>
它是根据宽度计算的,而不是父级的高度https://stackoverflow.com/questions/34706180/how-is-the-margin-top-percentage-calculated
现在剩下的唯一问题是如何计算相对于宽度的高度