BS5 Grid XSmall
The Bootstrap 5 Grid XSmall system provides responsive design capabilities for extra-small devices, typically screens smaller than 576px. You can use .col-*
classes to define the number of columns for this screen size.
Key Topics
Basic XSmall Columns
Create columns specifically for extra-small screens using the .col-*
classes.
<div class="container">
<div class="row">
<div class="col-6">XSmall Column 1</div>
<div class="col-6">XSmall Column 2</div>
</div>
</div>
Explanation: Use the .col-*
classes to divide the grid for extra-small devices. In this example, each column takes up half the width of the row.
Nested XSmall Columns
Nest rows and columns within an extra-small column for more complex layouts.
<div class="container">
<div class="row">
<div class="col-12">
XSmall Parent Column
<div class="row mt-2">
<div class="col-6">Nested Column 1</div>
<div class="col-6">Nested Column 2</div>
</div>
</div>
</div>
</div>
Explanation: This example demonstrates nesting rows and columns within an extra-small parent column.
Custom Width for XSmall
Set custom widths for columns on extra-small screens using the .col-*
classes.
<div class="container">
<div class="row">
<div class="col-4">Column 1 (4 units)</div>
<div class="col-8">Column 2 (8 units)</div>
</div>
</div>
Explanation: Adjust the column width proportionally using the .col-*
classes for extra-small screens.
Complete XSmall Grid Example
Below is a complete example of the grid system for extra-small screens, including basic, nested, and custom-width columns.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Bootstrap 5 Grid XSmall Demo</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
</head>
<body>
<div class="container my-4">
<h2 class="text-center">Bootstrap Grid XSmall</h2>
<div class="row mb-3">
<div class="col-6">XSmall Column 1</div>
<div class="col-6">XSmall Column 2</div>
</div>
<div class="row mb-3">
<div class="col-12">
Parent Column
<div class="row mt-2">
<div class="col-6">Nested Column 1</div>
<div class="col-6">Nested Column 2</div>
</div>
</div>
</div>
<div class="row">
<div class="col-4">Custom Column 1</div>
<div class="col-8">Custom Column 2</div>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>
Explanation: This example demonstrates various configurations of the grid system for extra-small screens, including nested and custom-width columns.
Key Takeaways
- Use
.col-*
classes to define grid layouts for extra-small screens. - Nest rows and columns within a parent column for advanced layouts.
- Adjust column width dynamically for extra-small devices using proportional classes.