Hey there! π I’m Vikas Sankhla, your big tech brother from Web Codder. Today, weβre going to learn how web pages adjust themselves on phones, tablets, and computers using CSS layouts. Letβs dive into this fun ride like weβre building Lego houses that change shape on demand! π§±π±π»
π― What Are CSS Layouts?
CSS Layouts help us arrange content on a web pageβlike putting furniture in a room. ποΈ
It tells the browser where things should go and how they should behave on different screen sizes.
There are many layout techniques, but weβll focus on the most useful and modern ones:
- Flexbox
- Grid
- Positioning
- Media Queries
π§ Flexbox β One-Dimensional Layout Tool
Flexbox is like a smart row or column that adjusts its items.
π€ΉββοΈ Use Case:
Perfect for navigation bars, cards in a row, or aligning things in a straight line.
π§ͺ Example:
<div class="container">
<div>Box 1</div>
<div>Box 2</div>
<div>Box 3</div>
</div>
.container {
display: flex;
justify-content: space-between;
}
π Key Properties:
display: flex
justify-content
align-items
flex-direction

π§± Grid β Two-Dimensional Layout Tool
Grid is like creating a spreadsheet layout. Rows and columns! π§©
π€ΉββοΈ Use Case:
Ideal for complex layouts, dashboards, galleries.
π§ͺ Example:
<div class="grid-container">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
.grid-container {
display: grid;
grid-template-columns: 1fr 1fr 1fr;
gap: 10px;
}
π Key Properties:
display: grid
grid-template-columns
grid-template-rows
gap

π Positioning Elements
Sometimes, we want to manually place items.
π Types:
static
(default)relative
absolute
fixed
sticky
π§ͺ Example:
.banner {
position: sticky;
top: 0;
}
π Sticky headers stay on top when you scroll. Super cool! π
π± Media Queries β Making Layouts Responsive
This is the magic that makes your website look good on all screens.
π§ͺ Example:
@media screen and (max-width: 600px) {
.container {
flex-direction: column;
}
}
If the screen is small (like a phone), items stack vertically. π±
![1.4 Css Layouts β Building Responsive Pages 3 Responsive Design Example]](https://webcodder.dev/wp-content/uploads/2025/05/Breakpoints-1024x536.webp)
π― Comparison Table β Flexbox vs Grid
Feature | Flexbox | Grid |
---|---|---|
Layout Type | One-Dimensional | Two-Dimensional |
Axis Control | Row or Column | Row and Column |
Use Case | Navbars, Cards | Dashboards, Galleries |
π§ Tips to Master Layouts
- Play with flexbox first. Itβs simple and powerful.
- Use grid for structured layouts.
- Combine media queries to make pages responsive.
- Inspect pages in browser DevTools to see layout in action. π
π¦ Bonus: CSS Units Cheat Sheet
Unit | Meaning |
---|---|
px | Pixels |
% | Percentage |
em/rem | Relative to font |
fr | Grid fraction |
π Conclusion
Now you know how to control your web page layout like a pro! π
Try building your own landing page using Flexbox and Grid.
And hey, donβt forget to follow us for more amazing guides! π
π Subscribe here: YouTube/WebCodder
π Explore tutorials: WebCodder Automation Blog
π¬ Connect with us: WhatsApp Community
See you in the next tech adventure! ππ¨βπ»