Experiment with Bootstrap components like grids, cards, and navbars.
By Codes With Pankaj
Step 1: Create a React App (if not already created)
If you don’t have a React app yet, create one by running:
Step 2: Install Bootstrap
Make sure Bootstrap is installed and imported in your project. If you haven't done this yet, follow the steps from the previous guide to install Bootstrap in your React app.
Step 3: Add a Navbar
A Navbar is a great way to create a navigation menu for your app. Here's how to add a basic responsive navbar using Bootstrap:
Open
src/App.js
and replace its content with the following code:Explanation:
navbar navbar-expand-lg navbar-dark bg-dark
: These classes style the navbar with a dark background and make it responsive.navbar-toggler
: The button that toggles the navbar on smaller screens.navbar-nav
: This is used to list the navigation links.
Step 4: Add a Grid Layout
Bootstrap’s grid system is a great way to organize content into columns and rows. Here’s how to use it:
Below the navbar in
App.js
, add a grid layout:Explanation:
col-md-4
: Creates a column that takes up 4/12 of the available space on medium-sized screens and above.card
: A Bootstrap component used for displaying content in a flexible and concise container.card-body
,card-title
,card-text
: These classes are used to style the contents of each card.
Step 5: Add a Card Component
In the above step, we already added some cards inside the grid layout. Here's a deeper dive into how to use the Bootstrap Card component:
Each card can contain different content such as images, titles, and text.
The
img
tag inside each card shows a placeholder image.
Step 6: Run Your Project
Start the development server if you haven't already:
Open your browser at
http://localhost:3000
.
You should see:
A navbar at the top of the page.
A grid layout with three cards, each containing an image and text.
Conclusion
You’ve successfully implemented several Bootstrap components in your React app:
Navbar for navigation.
Grid Layout to organize content.
Cards to display information dynamically.
Next Steps
Learn how to customize Bootstrap with SCSS to change colors and layout styles.
Stay tuned for more tutorials on Codes With Pankaj! 😊
Last updated