由于某些原因,我的固定头部高度为0。如何使头部div采用其子元素header-title的高度?我正在尝试在动态分辨率下显示固定头部下方的内容。在线解决方案适用于包含浮动元素的div;但这不是这里发生的事情。 CodePen:http://codepen.io/samaraiza/pen/czajq
HTML:
<div class="container">
<div class="header">
<div class="header-title"> Cool Title </div>
</div>
<div class="content"> Cool Content </div>
</div>
CSS:
.container {
position: absolute;
width: 100%;
height: 100%;
background: green;
}
.header {
position: relative;
width: 100%;
height: auto;
background: yellow;
text-align: center;
font-size: 3vw;
}
.header-title {
position: fixed;
width: 100%;
background: red;
}
.content {
position: relative;
font-size: 1.5vw;
}
谢谢大家!
.header-title
的高度。然后将CSS样式添加到.content
类中,其中包含margin-top:(header-title元素的高度)
。 - Zedrianposition:fixed
会将其从流中移除,因此它无法影响其他元素的定位。您将不得不使用JavaScript(或为标题定义最大高度并以此方式分隔内容。然后它就不是动态的了,我知道)。 - lukasgeiter