Navbar
Goal
- âš¡ In this step we are going to create Navbar.
Navbar
component.
Copy the code of First, copy the code of the Navbar component from the link below. https://getbootstrap.com/docs/4.5/components/navbar/
Next, paste the copied code into index.html
.
Organize the code of the Navbar
Now, let's remove the unnecessary code from the Navbar and add a nav-item
.
The final code looks like this.
If it looks like the following, you should be fine.
Sign Up Button
Next, let's add a Sign Up button. Please copy and paste the code as follows.
Bootstrap ref
The Bootstrap classes used here are the followings.
btn btn-warning
to add a button: https://getbootstrap.com/docs/4.5/components/buttons/#examplesfont-weight-bold
to make the text bold: https://getbootstrap.com/docs/4.5/utilities/text/#font-weight-and-italicspx-3 py-2
to adjust padding: https://getbootstrap.com/docs/4.5/utilities/spacing/
The current output looks like this.
Logo
So let's add logo next.
First, let's create a dummy logo on the following site.
https://favicon.io/favicon-generator/
Unzip the downloaded zip file and move android-chrome-192x192.png
from it to the img
folder.
Then rename it as logo.png
.
Load this logo.png
inside navbar-brand
.
It looks like the following.
However, the size of the logo is too large, so let's add attributes by referring to the following link. https://getbootstrap.com/docs/4.5/components/navbar/#brand
It became just the right size logo, as shown below.
Logo title
Next, let's change the character from "Navbar" to "Logo", enclose it in span
and add the Bootstrap class font-weight-bold
.
It looks like the following.
Change the background color of Navbar
Let's change the background color of Navbar from bg-light
to bg-white
class as follows.
It looks like the following.
https://getbootstrap.com/docs/4.5/utilities/colors/#background-color
Shadow
Add the class shadow-sm
to add a shadow to the navbar to give it a three-dimensional effect.
It looks like the following.
https://getbootstrap.com/docs/4.5/utilities/shadows/
Sticky navbar
Let's add a sticky-top
class to make the navbar sticky.
https://getbootstrap.com/docs/4.5/utilities/position/#sticky-top
However, we can't see the difference of the sticky-top
because there is no content currently and we can't scroll. So, check the following link.
https://getbootstrap.com/docs/4.5/examples/product/
If you add sticky-top
, the navbar remains fixed on the top of screen.
Adjusting Margin
Let's add ml-auto
and mr-lg-4
to adjust the margins.
It looks like the following.
Adding Custom CSS
Please add the following CSS for minor visual adjustments.
Final Code
The final code looks like this