Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

top nav bar blocking top content of the page

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?

like image 502
GeekedOut Avatar asked Apr 26 '12 15:04

GeekedOut


People also ask

How do you fix a navigation bar on top?

To create a fixed top menu, use position:fixed and top:0 .

Why is my nav bar not at the top?

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.

How do I stop navbar from overlapping?

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.

How do I make the navbar transparent on top?

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.


1 Answers

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;   } } 
like image 191
Spajus Avatar answered Sep 27 '22 20:09

Spajus