Featured Project
Spans two columns on desktop.
health-check domain was triggered too early. This is usually an indicator for some code in the plugin or theme running too early. Translations should be loaded at the init action or later. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /home/yogisv5/sitesbyyogi.com/wp-includes/functions.php on line 6260Objective: Learn how to position and align elements using CSS Flexbox and Grid β modern, powerful layout systems.
Flexbox arranges elements along a single axis β a row or a column.
<div class="container">
<div class="box">1</div>
<div class="box">2</div>
<div class="box">3</div>
</div>
/* CSS */
.container {
display: flex;
background-color: #eee;
padding: 10px;
}
.box {
background-color: #0E477B;
color: white;
padding: 20px;
margin: 10px;
flex: 1;
text-align: center;
}
β Flex items line up in a row by default.
.container {
display: flex;
flex-direction: row; /* default: row | row-reverse | column | column-reverse */
}
.container {
display: flex;
justify-content: space-between; /* main axis */
align-items: center; /* cross axis */
gap: 20px; /* spacing between items */
}
| Property | Aligns | Common Values |
|---|---|---|
justify-content | horizontally | flex-start, center, space-between, space-around, space-evenly |
align-items | vertically | flex-start, center, stretch, baseline |
align-content | multi-line | same values as above |
/* Equal growth */
.box { flex: 1; }
/* Custom proportions */
.box1 { flex: 2; } /* twice as wide */
.box2 { flex: 1; }
Responsive without media queries for many row layouts.
<header class="nav-bar">
<div class="logo">StreetGeek</div>
<nav>
<a href="#">Home</a>
<a href="#">Courses</a>
<a href="#">Contact</a>
</nav>
</header>
.nav-bar {
display:flex;
justify-content:space-between;
align-items:center;
background:#0E477B;
color:#fff;
padding:10px 20px;
}
.nav-bar nav{ display:flex; gap:15px; }
.nav-bar a{ color:#fff; text-decoration:none; }
.nav-bar a:hover{ text-decoration:underline; }
@media (max-width:768px){
.nav-bar{ flex-direction:column; gap:10px; }
}
Grid is two-dimensional β control rows and columns.
<div class="grid">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
/* CSS */
.grid{
display:grid;
grid-template-columns:repeat(2, 1fr);
gap:20px;
}
.item{
background:#6EC1E4; color:#fff; padding:20px; text-align:center;
}
β
2 equal columns using repeat(2,1fr).
| Property | Example | Description |
|---|---|---|
grid-template-columns | repeat(3, 1fr) | Number/width of columns |
grid-template-rows | 200px auto | Row heights |
gap | 20px | Space between items |
grid-column | 1 / 3 | Span multiple columns |
grid-row | 2 / 4 | Span multiple rows |
π‘ fr is a fractional unit β βone part of the available spaceβ.
<div class="layout">
<header>Header</header>
<nav>Nav</nav>
<main>Main Content</main>
<aside>Sidebar</aside>
<footer>Footer</footer>
</div>
.layout{
display:grid;
grid-template-areas:
"header header"
"nav main"
"nav aside"
"footer footer";
grid-template-columns:1fr 3fr;
gap:10px;
}
.layout header{ grid-area:header; background:#0E477B; color:#fff; padding:20px; }
.layout nav { grid-area:nav; background:#e5e5e5; padding:20px; }
.layout main { grid-area:main; background:#f8f8f8; padding:20px; }
.layout aside { grid-area:aside; background:#ddd; padding:20px; }
.layout footer{ grid-area:footer; background:#0E477B; color:#fff; padding:20px; }
@media (max-width:768px){
.grid{ grid-template-columns:1fr; } /* stack grid */
.nav-bar{ flex-direction:column; } /* stack flex */
}
gap: 20px; do?Create a responsive portfolio layout using both systems:
gap; hover effect on cards..featured { grid-column: span 2; }
Spans two columns on desktop.
Hover me.
Hover me.
Hover me.
Hover me.
justify-content, align-items, and gap.Next up: π MODULE 8: Colors, Fonts & Visual Design β color theory, typography, and hierarchy.