How to position a fixed div under another fixed div?

假装没事ソ 提交于 2019-12-25 03:33:07

问题


I am trying to set a fixed div div(menu) directly under another fixed div (header) and the positioning should also work with different screen sizes. I call the "menu" div through JQuery with toggle and it appears under the "header" div. I can do this setting a fixed top value greater than the height of the "header" div but if I do not want the header to have a fixed PX value how do I do this? Any suggestions?

html:

<div id="header">
 <div id="menu">
 </div>
</div>

css:

#header{
  position:fixed
  height:15%;
  width:100%;
  background-color:blue;
}

#dropdown{
  display:none;
  position:fixed;
  top:?
}

回答1:


Have a wrapper that is fixed, and just have the other 2 divs flow traditionally.

#header-container {
  position:fixed
  height:15%;
  width:100%;
  background-color:blue;
}    
#header, #dropdown {
  width:100%;
}

<div id="header-container">
    <div id="header">
    </div>
    <div id="dropdown">
    </div>
</div>


来源:https://stackoverflow.com/questions/30035230/how-to-position-a-fixed-div-under-another-fixed-div

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