0

I have a navbar with a z-index that is above/higher all other elements on a page, which means it is "ignored". Its height is not counted on the page.

Also, I am using Twitter Bootstrap as my website's foundation.

What happens when I try to redirect to an element with anchor tag. Example:

<a href="#idhere">Go to ID</a>

Part of the element I redirected to will get covered (covered element = navbar height) by the navbar since its height is not counted on the page.

I'm sure there is a fix to this with JS/jQuery but I would like to know if I can do it through just HTML & CSS.

Thank you. And please do ask for clarification if I did not address my question clear enough.

123
  • 3
  • 1
  • See this question : [offsetting an html anchor to adjust for fixed header](http://stackoverflow.com/questions/10732690/offsetting-an-html-anchor-to-adjust-for-fixed-header) – Michel Apr 18 '14 at 13:49

2 Answers2

0

I used to use a small trick (I think it still works), just do:

<div id="mydiv" class="section-target"></div>

And the CSS:

.section-target {
    margin-top: -40px ; // Change to your navbar height
    padding-top: 40px ;
}
Holt
  • 36,600
  • 7
  • 92
  • 139
0

Have a look at the docs here: Bootstrap - Navbar fixed top

It recommends you adjust the padding of the whole body, to compensate for the height of the nav-bar:

body { padding-top: 70px; }

You can also use the static top navbar, which does not require the extra padding: Bootstrap - Navbar static top

jackfrankland
  • 2,052
  • 1
  • 13
  • 11