Navbar-fixed-top pushes content on page up

五迷三道 提交于 2019-12-25 04:22:19

问题


I currently have a navbar at the top of my page that is static, but when I try to make it fixed, it always "eats" the content below it.

Bootply when it's static
Bootply when it's fixed

Is there any way to fix this?


回答1:


When you add the navbar-fixed-top class to your nav bar, it applies two main CSS properties:

position: fixed;
top: 0;

This fixes the div to the top of the page. Doing that however means the following div starts exactly where the nav bar previously was. Think like this, the nav bar is now floating around so everything else is unaware of it's existence. So you need to push the rest of your page down slightly to compensate.

Just put a margin-top on the body content to push it down.

margin-top: 60px; 

In full, I added this to the CSS:

.body-content {
  margin-top: 60px;
}

Then added the body-content class to the next container.

Works like this: http://www.bootply.com/QlRuLAUtwN



来源:https://stackoverflow.com/questions/24639086/navbar-fixed-top-pushes-content-on-page-up

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