1 Step 1: Columns with grid-template-columns 2 Step 2: A featured item that spans columns ⚡ 0 XP हिंदी
Learn Code Result
Step 1 of 2
Columns with grid-template-columns grid-template-columns: repeat(3, 1fr)
Flexbox is great for one row. Grid handles rows and columns together — perfect for a product gallery.
display: grid; on the parentgrid-template-columns: repeat(3, 1fr); — three equal columns (fr = a fraction of the free space)gap: 12px; — space between rows and columnsThe children fill the grid automatically, left to right, row by row.
Example Copy .gallery {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
}🎯 Challenge: Toy shop gallery +20 XP Turn .gallery into a grid with columns (for example three equal columns with repeat(3, 1fr)) and a gap.
💡 Get a hint (0/3) 🔑 Show solution
Try twice to unlock the solution (0/2)
style.css Ctrl ⏎ ↺ Reset ▶ Run & check
Console
Output from console.log appears here.
Checklist
Press Run to check your code.
Lesson notes (text version) 1. Columns with grid-template-columns Flexbox is great for one row. Grid handles rows and columns together — perfect for a product gallery.
display: grid; on the parentgrid-template-columns: repeat(3, 1fr); — three equal columns (fr = a fraction of the free space)gap: 12px; — space between rows and columnsThe children fill the grid automatically, left to right, row by row.
.gallery {
display: grid;
grid-template-columns: repeat(3, 1fr);
gap: 12px;
}
Challenge: Toy shop gallery Turn .gallery into a grid with columns (for example three equal columns with repeat(3, 1fr)) and a gap.
2. A featured item that spans columns A grid child can take up more than one cell. grid-column: span 2; makes an item two columns wide — great for a "Deal of the day" or a featured product.
You can also give a start and end line: grid-column: 1 / 3; means "from line 1 to line 3", which is also two columns.
.featured {
grid-column: span 2;
background-color: gold;
}
Challenge: Deal of the day The gallery grid is ready. Make the .featured item span 2 columns and give it a different background colour so it stands out.
The interactive editor needs JavaScript. The lesson notes above work without it.