Rows and columns help you organize content neatly on a webpage. They make your page look good on all screen sizes.
Row and column structure in Bootsrap
<div class="container"> <div class="row"> <div class="col">Content here</div> <div class="col">More content</div> </div> </div>
The row class groups columns horizontally.
The col class creates flexible columns inside a row.
<div class="row"> <div class="col">One column</div> </div>
<div class="row"> <div class="col-6">Half width</div> <div class="col-6">Half width</div> </div>
<div class="row"> <div class="col-4">One third</div> <div class="col-8">Two thirds</div> </div>
This example shows three equal columns inside a row. Each column has background color and padding to see the layout clearly. The page adjusts nicely on different screen sizes.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Bootstrap Row and Column Example</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body> <div class="container mt-4"> <h1 class="mb-3">Row and Column Structure</h1> <div class="row"> <div class="col-4 bg-primary text-white p-3">Column 1 (4 units)</div> <div class="col-4 bg-success text-white p-3">Column 2 (4 units)</div> <div class="col-4 bg-danger text-white p-3">Column 3 (4 units)</div> </div> </div> </body> </html>
Bootstrap grid uses 12 units per row. Columns add up to 12 for full width.
Use col without a number for equal width columns automatically.
Rows have negative margins; always place columns inside rows to avoid layout issues.
Rows group columns horizontally to create layouts.
Columns divide the row space and can have fixed or flexible widths.
Using rows and columns helps build responsive and neat web pages easily.
Practice
.row in Bootstrap's grid system?Solution
Step 1: Understand the role of
The.row.rowclass in Bootstrap groups columns horizontally to create a structured layout.Step 2: Differentiate from other classes
Other classes like padding or buttons serve different purposes, not layout grouping.Final Answer:
To group columns horizontally and manage their layout -> Option DQuick Check:
Row groups columns [OK]
- Thinking rows add padding or style
- Confusing rows with buttons or backgrounds
- Assuming rows create vertical stacks
Solution
Step 1: Identify correct Bootstrap column syntax
Bootstrap usescolclasses inside arowto create equal-width columns.Step 2: Check each option
usescolinsiderow, which creates three equal columns automatically.Final Answer:
<div class='row'><div class='col'></div><div class='col'></div><div class='col'></div></div> -> Option AQuick Check:
Usecolinsiderowfor equal columns [OK]
col inside row for equal columns [OK]- Using
containerinstead ofrowfor columns - Using non-Bootstrap class names like
column - Using fixed column sizes unnecessarily
<div class='row'> <div class='col-6'>Left</div> <div class='col-6'>Right</div> </div>
Solution
Step 1: Understand
Eachcol-6in Bootstrap gridcol-6takes 6 of 12 parts, so half the row width.Step 2: Visualize the layout
Twocol-6columns inside arowappear side by side, each half width.Final Answer:
Two columns side by side, each taking half the row width -> Option AQuick Check:
col-6+col-6= two halves side by side [OK]
- Thinking columns stack vertically by default
- Assuming columns overlap without floats or flex
- Confusing
col-6with full width
<div class='row'> <div class='col-8'>Content</div> <div class='col-6'>Sidebar</div> </div>
Solution
Step 1: Calculate total column widths
col-8+col-6= 14, which is more than 12 grid units.Step 2: Understand Bootstrap grid limits
Bootstrap grid rows should have columns summing to 12 or less to avoid wrapping or overflow.Final Answer:
The total column width exceeds 12, causing layout issues -> Option CQuick Check:
Sum of columns > 12 breaks layout [OK]
- Ignoring total column width sum
- Thinking
containeris mandatory for rows - Confusing class names like
columninstead ofrow
Solution
Step 1: Check the sum of column widths
3 + 3 + 4 + 2 = 12, which fits perfectly in Bootstrap's 12-grid system.Step 2: Match the order of columns to the question
The first column should be 3, second 3, third 4, and last 2, matchingcol-3,col-3,col-4,col-2exactly.Final Answer:
col-3, col-3, col-4, col-2 -> Option BQuick Check:
Sum 12 and order match [OK]
- Choosing columns that sum more or less than 12
- Mixing column order
- Using equal columns when specific widths are needed
Ready to prove it?
Pass the test and this pattern moves unknown
