Fixating the navbar

Our website already looks pretty decent. We have a navigation bar in place, a footer placeholder, and various sections populated with some sample content. However, we are not quite there yet. The website's overall user experience is still a bit edgy and does not yet feel very refined. Take navigation, for instance—while clicking on a navbar link does indeed take the user to the correct section, the navbar disappears once we navigate across the sections. This means that the navbar loses its purpose. It no longer facilitates easy navigation across the different sections of our website. Instead, the user will need to scroll to the top of the page every time they wish to use the navbar. To make the navbar persistent, append navbar-fixed-top to the class attribute of our nav element:

<nav class="navbar navbar-expand-lg navbar-myphoto fixed-top">
...
</nav>

Now save, refresh, and scroll. Voila! Our navbar now remains fixed at the top of our page. The fixed-top works as follows: the element's position is set to fixed. This positions the element relative to the browser window (not relative to other elements), meaning that the element will remain in the same place, regardless of the positioning of other elements on the page—that is, fixed navbars are pulled from the normal flow of the DOM and may require custom CSS.

Furthermore, the element's top is set to 0. This means that the distance between the navbar and the top of the browser window is 0. In addition, fixed-top also changes the element's z-index to 1,030, therefore ensuring that the element will appear above all the other elements on the page (that is, all elements that have a z-index of less than 1,030).

The fixed-top class is defined in _position.scss and looks as follows:

.fixed-top {
position: fixed;
top: 0;
right: 0;
left: 0;
z-index: $zindex-fixed;
}

Note: $zindex-fixed is defined in _variables.scss, and its default value is 1030.

Did you know that within web development, another term for persistent is sticky? For example, instead of asking "How can I make my navbar persistent?", you often hear people asking "How do I make my navbar sticky?". Note that position: fixed is not the same as position: sticky. The latter isn't fully supported in every browser.

Should you desire to fixate the navbar at the bottom of the page, you can use the fixed-bottom class. This class behaves in exactly the same way as the fixed-top class, except that instead of setting the element's top to 0, it sets the bottom property to 0, thereby ensuring that the element resides at the bottom of the page.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.66.31