Contents
If your navbar is on the top of the page originally, set the value to 0. Otherwise, set the value for data-offset-top to the value of the content above your navbar. Highly active question. Earn 10 reputation (not counting the association bonus) in order to answer this question.
My issue is that I fixed a navigation bar at the top of my webpage and it includes both side margins and top one. Below this navigation bar, I want to set an scrollable container. Let me say I’m using Bootstrap 3.2.0 to lay out the site.
How to block the top of the page in CSS?
The bootstrap v4 starter template css uses: As seen on this example from Twitter, add this before the line that includes the responsive styles declarations: using percentage is much better solution than pixels. body { padding-top: 10%; //This works regardless of display size. }
How to make your Div scroll behind The navbar?
If you don’t want your body to scroll behind the navbar, change your CSS to use padding instead of margin: you can simply get this fixed by updating your margins to paddings.. and update the div like the below.. If you want to scroll on the div (not on the page) then add the class “scroll” to your scrolling div and update css with:
The fixed navbar will overlay your other content, unless you add padding to the top of the body. 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.
For bootstrap 3, the class navbar-static-top instead of navbar-fixed-top prevents this issue, unless you need the navbar to always be visible. a much more handy solution for your reference, it works perfect in all of my projects:
Is there a way to fix the height of The navbar?
It’s possible setting a variable for the paddingTop of the body to the height of the navbar could also work and is subsequently a bit more responsive than a fixed 60/65px value.
What does a fixed navbar do in CSS?
In other words, a fixed or sticky navbar stays in place while you are scrolling the web page. They allow showing interface components regardless of where the user is on a web page. A fixed navbar is simple to create. It requires a little HTML markup and only a few CSS properties.
In our examples we will build the navigation bar from a standard HTML list. A navigation bar is basically a list of links, so using the and elements makes perfect sense: list-style-type: none; – Removes the bullets. A navigation bar does not need list markers
Create a element with the class “navbar”. Add tags inside the . With the tags, we use href attribute, which is a required attribute of the tag. It specifies a link on the web page or a place on the same web page, where the user navigates after clicking on the link. Give each of them an id and input the content.