HTML – Stack 2固定Div总是顶部

前端之家收集整理的这篇文章主要介绍了HTML – Stack 2固定Div总是顶部前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我试图找出最简单的方法来堆叠2固定div一个是动态的,一个是静态的.

我的导航高度为76px固定位置.但我在顶部有另一个div,它将根据数据库值隐藏或显示.它将所有东西都按下应用,问题是当我滚动导航器它应该在哪里但是消息div滚动它的身体应该保持在导航div的顶部.

  1. .nav {
  2. background-color: #000;
  3. height: 76px;
  4. width: 100%;
  5. position: fixed;
  6. z-index: 100;
  7. }
  8. .message{
  9. background-color: #ff0000;
  10. height: 50px;
  11. width: 100%;
  12. }
最佳答案
只需将固定位置添加到.message,然后向导航添加50px的margin-top,如下所示:

  1. .nav {
  2. background-color: #000;
  3. height: 76px;
  4. width: 100%;
  5. position: fixed;
  6. margin-top: 50px;
  7. z-index: 100;
  8. color:#fff;
  9. }
  10. .message{
  11. background-color: #ff0000;
  12. height: 50px;
  13. width: 100%;
  14. position: fixed;
  15. }

猜你在找的HTML相关文章