Container after fixed navbar with dynamic height

假装没事ソ 提交于 2019-12-11 05:19:01

问题


I have a header with a dynamic height (min-height: 50px).

Of course, it can be higher than 50px. I want a container with some content right below it.

Can I do that with a margin or some other formatting?


回答1:


Do you mean somthing like that?

body {
  height: 500px;
  background-image: linear-gradient(to bottom, #eee 0%, #000011 100%);
}
.header-container {
  position: fixed;
  width: 100%;
  top: 0px;
  left: 0px;
}
.header {
  min-height: 50px;
  padding: 15px;
  background-color: #72f072;
}
.header-container .header p,
.header-container .something p {
  margin: 0px;
}
.header-container .something {
  padding: 15px;
  background-color: #fff;
}
<div class="header-container">
  <div class="header">
    <p>some content</p>
  </div>
  <div class="something">
    <p>some other content</p>
  </div>
</div>



回答2:


get the header height and assign margin top to content div using js.

var height = document.getElementById("head").offsetHeight;
document.getElementById("content").style.marginTop = height + 'px';



回答3:


You should give to the container a margin-top equal to the fixed navbar height. But as the navbar height may need to grow, I usually change the height and the container margin, as needed, with media queries.



来源:https://stackoverflow.com/questions/44277605/container-after-fixed-navbar-with-dynamic-height

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!