-
Hajipur, Bihar, 844101
A Responsive Grid View is a layout that adjusts the number of columns and the size of items based on the screen size or device width. It is widely used for:
Image galleries
Product listings
Portfolio layouts
Blog post grids
Cards and dashboards
With CSS Grid or Flexbox, we can make grids that automatically adjust on mobile, tablet, and desktop.
%
, fr
, or auto
instead of fixed px
.<div class="grid">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
<div class="item">4</div>
</div>
.grid {
display: flex;
flex-wrap: wrap;
gap: 10px;
}
.item {
flex: 1 1 calc(25% - 10px); /* 4 columns */
background: #ddd;
padding: 20px;
box-sizing: border-box;
}
@media (max-width: 768px) {
.item {
flex: 1 1 calc(50% - 10px); /* 2 columns */
}
}
@media (max-width: 480px) {
.item {
flex: 1 1 100%; /* 1 column */
}
}
.grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
gap: 15px;
}
This allows the number of columns to auto-adjust based on screen size.
✅ Use auto-fit
or auto-fill
✅ Keep minimum column width using minmax()
✅ Always define gap
between items
✅ Use box-sizing: border-box
to avoid width overflow
✅ Test your layout on multiple devices
✅ Write HTML/CSS for the following:
Q1. Create a 3-column grid that adjusts to 2 columns below 768px and 1 column below 480px.
Q2. Make an image gallery with equal-sized responsive grid items.
Q3. Build a card layout using Flexbox grid with wrapping.
Q4. Use auto-fit
with minmax(150px, 1fr)
to create a dynamic grid.
Q5. Add space between grid items using gap
.
Q6. Use media queries to change the number of columns.
Q7. Make the grid container full width and center the items.
Q8. Add hover effects to grid items that scale on hover.
Q9. Create a grid where the first item spans two columns.
Q10. Combine grid layout with responsive images inside each item.
Q1: Which CSS property enables a grid layout?
Q2: What does auto-fit do in grid-template-columns?
Q3: What does minmax(200px, 1fr) mean?
Q4: Which unit is ideal for responsive column widths?
Q5: Which property adds spacing between grid items?
Q6: What is the role of flex-wrap: wrap in a Flexbox grid?
Q7: How do you ensure padding doesn’t break grid layout width?
Q8: Which value of flex creates a 25% width item?
Q9: What happens when screen is below media query width?
Q10: Which is the correct responsive grid layout property?