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 containe
I really don't like having to add elements that are just there for purposes of pushing content around. This is what positioning is designed to handle. The best way to do this is to start by adding padding to the top of your body, as @davidg stated in his answer. Further, to move your navbar into position, don't use margins. Instead using the top, left and right properties. The navbar-fixed-top class already sets the position to fixed, so you don't need to give any position property value. I also added the container-fluid class to your div (so that you get some padding inside) and a custom class scrollable to set the overflow property.
CSS:
html, body {
height: 100%; /*Fixes the height to 100% of the viewport*/
}
body {
padding-top: 87px; /*50px for the height of the navbar + 37px for the offset*/
padding-bottom: 50px; /*50px for the height of the bottom navbar*/
}
.navbar-offset {
top: 37px; /*Offsets the top navbar 37px from the top of the viewport*/
}
.container-fluid.scrollable {
height: 100%; /*Sets the scrollable area to 100% of the viewport*/
overflow: auto; /*Allows the scrollable area to have a scrollbar based on the height of its content*/
background: #ccc;
}
HTML:
BEGIN
Hi World
...
END