Here are 5 **Bootstrap layouts** you can create, ranging from basic to intermediate, using **Bootstrap 5.3**. I'll explain each layout and provide details on how to structure them, including some visual breakdowns.
---
### **1. Two-Column Layout (Content + Sidebar)**
#### **Description:**
This is a simple **two-column layout** often used for blogs or news websites where the main content appears on one side and a sidebar (with widgets, ads, or navigation) is on the other side.
#### **Structure:**
- **Left Column**: Main content (e.g., articles, blog posts).
- **Right Column**: Sidebar with navigation, recent posts, or widgets.
#### **Bootstrap Classes Used:**
- **`container`**: To wrap the layout.
- **`row`**: To create a horizontal group of columns.
- **`col-md-8`**: A 2/3rd column for the main content.
- **`col-md-4`**: A 1/3rd column for the sidebar.
#### **Visual Example:**
```html
<div class="container">
<div class="row">
<div class="col-md-8">
<!-- Main content here -->
</div>
<div class="col-md-4">
<!-- Sidebar content here -->
</div>
</div>
</div>
```
**Drawing**:
```
+-----------------------+------------------+
| Main Content (2/3) | Sidebar (1/3) |
+-----------------------+------------------+
```
---
### **2. Three-Column Layout (Equal Columns)**
#### **Description:**
This is a **three-column layout** commonly used for dashboards, portfolios, or blogs. Each column is of equal width, and it adapts to screen size.
#### **Structure:**
- **3 Equal Columns**: Can be used for displaying portfolios, articles, or stats.
#### **Bootstrap Classes Used:**
- **`container`**
- **`row`**
- **`col-md-4`**: Three equal columns, each occupying 4 out of 12 grid spaces.
#### **Visual Example:**
```html
<div class="container">
<div class="row">
<div class="col-md-4">
<!-- Column 1 -->
</div>
<div class="col-md-4">
<!-- Column 2 -->
</div>
<div class="col-md-4">
<!-- Column 3 -->
</div>
</div>
</div>
```
**Drawing**:
```
+--------+--------+--------+
| Column | Column | Column |
+--------+--------+--------+
```
---
### **3. Hero Section with Cards Below**
#### **Description:**
A landing page layout with a **hero section** at the top and **cards** below. This layout is great for product showcases or services.
#### **Structure:**
- **Hero Section**: A full-width header that introduces the product or service.
- **Three Cards Below**: Used to showcase features, services, or products.
#### **Bootstrap Classes Used:**
- **`container-fluid`**: For the full-width hero section.
- **`row`**, **`col-md-4`**: For arranging cards.
#### **Visual Example:**
```html
<div class="container-fluid bg-primary text-white text-center p-5">
<h1>Welcome to Our Website</h1>
<p>We offer amazing services</p>
</div>
<div class="container py-5">
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-body">Service 1</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">Service 2</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">Service 3</div>
</div>
</div>
</div>
</div>
```
**Drawing**:
```
+------------------------------------------+
| Hero Section |
+------------------------------------------+
| | | | |
| Card 1 | Card 2 | Card 3 | |
+--------+---------+---------+-------------+
```
---
### **4. Dashboard Layout**
#### **Description:**
A dashboard layout with a **sidebar** for navigation and a **main content area** for displaying data, graphs, or controls.
#### **Structure:**
- **Sidebar (fixed)**: On the left for navigation.
- **Main Content**: On the right for the dashboard's main content, such as charts or reports.
#### **Bootstrap Classes Used:**
- **`container-fluid`**: For a full-width layout.
- **`row`**: To separate the sidebar and main content.
- **`col-md-2`**: Sidebar column.
- **`col-md-10`**: Main content column.
#### **Visual Example:**
```html
<div class="container-fluid">
<div class="row">
<div class="col-md-2 bg-dark text-white vh-100">
<!-- Sidebar content -->
</div>
<div class="col-md-10">
<!-- Main dashboard content -->
</div>
</div>
</div>
```
**Drawing**:
```
+-------+----------------------------+
|Sidebar| Main Dashboard Content |
+-------+----------------------------+
```
---
### **5. Grid Gallery Layout**
#### **Description:**
This is a **grid layout** for showcasing images or items in a gallery. It uses a flexible number of columns based on screen size, making it perfect for portfolios or photo galleries.
#### **Structure:**
- **Images in a grid**: Each image or card adjusts its size to the screen size.
#### **Bootstrap Classes Used:**
- **`container`**
- **`row`**
- **`col-sm-6`**: Two columns on small screens.
- **`col-md-4`**: Three columns on medium screens.
- **`col-lg-3`**: Four columns on large screens.
#### **Visual Example:**
```html
<div class="container py-5">
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3">
<img src="image1.jpg" class="img-fluid">
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<img src="image2.jpg" class="img-fluid">
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<img src="image3.jpg" class="img-fluid">
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<img src="image4.jpg" class="img-fluid">
</div>
</div>
</div>
```
**Drawing**:
```
+--------+--------+--------+--------+
| Image | Image | Image | Image |
+--------+--------+--------+--------+
| Image | Image | Image | Image |
+--------+--------+--------+--------+
```
---
These layouts can be easily customized with Bootstrap 5.3 classes and will adjust smoothly to different screen sizes, ensuring responsive designs.
Here’s a detailed explanation of all the **Bootstrap 5.3** classes used in the 5 layouts provided earlier:
---
### **1. Two-Column Layout (Content + Sidebar)**
```html
<div class="container">
<div class="row">
<div class="col-md-8">
<!-- Main content here -->
</div>
<div class="col-md-4">
<!-- Sidebar content here -->
</div>
</div>
</div>
```
- **`container`**: Wraps the layout to ensure the content stays within a responsive, fixed-width container based on screen size.
- **`row`**: Creates a horizontal group of columns. The `row` ensures that the columns are aligned in a single row and have no margin between them.
- **`col-md-8`**: Defines a column that takes up 8 out of the 12 available grid spaces on medium devices (≥768px) and larger. The width will automatically adjust on smaller screens.
- **`col-md-4`**: Defines a column that takes up the remaining 4 out of 12 grid spaces. This gives us a 2/3 + 1/3 split for the layout on medium and larger devices.
---
### **2. Three-Column Layout (Equal Columns)**
```html
<div class="container">
<div class="row">
<div class="col-md-4">
<!-- Column 1 -->
</div>
<div class="col-md-4">
<!-- Column 2 -->
</div>
<div class="col-md-4">
<!-- Column 3 -->
</div>
</div>
</div>
```
- **`container`**: Ensures the layout has a fixed width and adapts based on screen size.
- **`row`**: Groups the columns into a single row.
- **`col-md-4`**: Defines three equal-width columns, each taking up 4 out of 12 grid spaces. Each column will be 1/3 of the row's width on medium devices (≥768px) and larger. On smaller screens, they will stack vertically.
---
### **3. Hero Section with Cards Below**
#### Hero Section:
```html
<div class="container-fluid bg-primary text-white text-center p-5">
<h1>Welcome to Our Website</h1>
<p>We offer amazing services</p>
</div>
```
- **`container-fluid`**: Creates a full-width container that spans the entire width of the viewport, regardless of screen size.
- **`bg-primary`**: Applies a primary background color (typically a blue tone).
- **`text-white`**: Changes the text color to white to contrast with the primary background color.
- **`text-center`**: Centers all text horizontally within the container.
- **`p-5`**: Adds padding of `3rem` to all sides (the "5" refers to a specific padding scale in Bootstrap).
#### Cards Below:
```html
<div class="container py-5">
<div class="row">
<div class="col-md-4">
<div class="card">
<div class="card-body">Service 1</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">Service 2</div>
</div>
</div>
<div class="col-md-4">
<div class="card">
<div class="card-body">Service 3</div>
</div>
</div>
</div>
</div>
```
- **`container`**: Provides a responsive fixed-width container for the cards.
- **`py-5`**: Adds vertical padding (`3rem`) to both the top and bottom of the container.
- **`row`**: Groups the columns into a row.
- **`col-md-4`**: Defines three equal-width columns (4/12 each).
- **`card`**: The `card` class adds default styling for the card component, including padding, borders, and shadows.
- **`card-body`**: A section within the card for its main content.
---
### **4. Dashboard Layout**
```html
<div class="container-fluid">
<div class="row">
<div class="col-md-2 bg-dark text-white vh-100">
<!-- Sidebar content -->
</div>
<div class="col-md-10">
<!-- Main dashboard content -->
</div>
</div>
</div>
```
- **`container-fluid`**: Ensures the entire layout spans the full width of the viewport.
- **`row`**: Groups the sidebar and main content into a horizontal row.
- **`col-md-2`**: Defines a sidebar that takes up 2 out of 12 grid spaces on medium screens (≥768px) and larger.
- **`bg-dark`**: Applies a dark background color (usually black or dark gray).
- **`text-white`**: Ensures that text in the sidebar is white, offering contrast against the dark background.
- **`vh-100`**: Sets the sidebar's height to 100% of the viewport's height, making it a fixed-height sidebar.
---
### **5. Grid Gallery Layout**
```html
<div class="container py-5">
<div class="row">
<div class="col-sm-6 col-md-4 col-lg-3">
<img src="image1.jpg" class="img-fluid">
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<img src="image2.jpg" class="img-fluid">
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<img src="image3.jpg" class="img-fluid">
</div>
<div class="col-sm-6 col-md-4 col-lg-3">
<img src="image4.jpg" class="img-fluid">
</div>
</div>
</div>
```
- **`container`**: A fixed-width container for the grid layout.
- **`py-5`**: Adds padding to the top and bottom of the container.
- **`row`**: Wraps the grid items in a row.
- **`col-sm-6`**: On small screens (≥576px), each item takes up 6 out of 12 grid spaces, making it a 2-column layout.
- **`col-md-4`**: On medium screens (≥768px), each item takes up 4 out of 12 grid spaces, forming a 3-column layout.
- **`col-lg-3`**: On large screens (≥992px), each item takes up 3 out of 12 grid spaces, creating a 4-column layout.
- **`img-fluid`**: Ensures the images are responsive and adjust according to the container size, maintaining their aspect ratio.
---
### **Utility Classes Summary**
- **`container`**: Creates a centered, fixed-width container.
- **`container-fluid`**: Creates a full-width container that spans the entire width of the viewport.
- **`row`**: Used to wrap columns and control the horizontal layout within the grid system.
- **`col-md-X`, `col-sm-X`, `col-lg-X`**: Column classes for the grid system. `X` specifies how many of the 12 available grid spaces a column should span at a given screen size.
- **`bg-primary`**: Adds the primary theme color as a background.
- **`bg-dark`**: Adds a dark background.
- **`text-white`**: Changes text color to white.
- **`text-center`**: Centers text horizontally within its container.
- **`p-5` and `py-5`**: Adds padding of `3rem` on all sides (`p-5`) or on the vertical axis only (`py-5`).
- **`vh-100`**: Sets the element's height to 100% of the viewport height.
- **`card`, `card-body`**: Styles for Bootstrap's card component.
- **`img-fluid`**: Makes images responsive, ensuring they scale appropriately while maintaining aspect ratio.
These classes help structure and style layouts, ensuring responsiveness and a modern look.
0 Comments