I have this Twitter Bootstrap code
<div class='navbar navbar-fixed-top'> <div class='navbar-inner'> <div class='container'> <a class='btn btn-navbar' data-target='.nav-collapse' data-toggle='collapse'> <span class='icon-bar'></span> <span class='icon-bar'></span> <span class='icon-bar'></span> </a> <div class='nav-collapse'> <ul class='nav'> <li class='active'> <a href='some_url'>My Home</a> </li> <li> <a href='some_url'>Option 1 </a> </li> <li> <a href='some_url'>Another option</a> </li> <li> <a href='some_url'>Another option</a> </li> </ul> </div> </div> </div> </div>
But when I am viewing the beginning of the page, the nav bar is blocking some of the content that is near the top of the page. Any idea for how to make it push down the rest of the content lower when the top of the page is viewed so that the content isn't blocked by the nav bar?
To create a fixed top menu, use position:fixed and top:0 .
This is because of the browsers predefined CSS-Styles. Normally, you would reset the browsers CSS-styles, like giving everything a margin and padding of 0 or remove the bullet points from the li s. Check out Eric Meyers CSS Reset for example. put this on top of your CSS and everything will be fine.
Add a padding of the size of your navbar's height to the body. Show activity on this post. Since 2017 add position: sticky; top:0; to navbar and it will fix this problem.
Creating a transparent navbar is very easy - just don't add a color class . bg-* to the navbar. In this case, the Navbar will take the color of the parent's background color.
Adding a padding like that is not enough if you're using responsive bootstrap. In this case when you resize your window you'll get a gap between top of the page and navbar. A proper solution looks like this:
body { padding-top: 60px; } @media (max-width: 979px) { body { padding-top: 0px; } }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With