-
Hajipur, Bihar, 844101
Responsive Flexbox means using Flexbox properties in combination with media queries to make layouts adapt to different screen sizes — like mobile, tablet, and desktop.
Flexbox is naturally responsive because it automatically adjusts item sizes and spacing. You can use flex-wrap
, flex-direction
, gap
, and media queries to build layouts that work beautifully on all devices.
Property | Description |
---|---|
flex-wrap |
Allows items to wrap on smaller screens |
flex-direction |
Can switch from row to column on smaller screens |
flex |
Allows dynamic resizing of items |
gap |
Adds spacing between items without using margins |
media queries |
Customize layout per screen size |
<div class="flex-container">
<div class="box">Box 1</div>
<div class="box">Box 2</div>
<div class="box">Box 3</div>
</div>
.flex-container {
display: flex;
flex-wrap: wrap;
gap: 20px;
}
.box {
flex: 1 1 200px;
background: #eee;
padding: 20px;
text-align: center;
}
This layout will automatically wrap boxes when screen width is limited.
@media (max-width: 600px) {
.flex-container {
flex-direction: column;
}
}
This changes the layout from row to column on smaller screens.
<nav class="navbar">
<div class="logo">Logo</div>
<div class="links">
<a href="#">Home</a>
<a href="#">About</a>
<a href="#">Contact</a>
</div>
</nav>
.navbar {
display: flex;
justify-content: space-between;
flex-wrap: wrap;
padding: 10px;
}
.links a {
margin-left: 15px;
}
@media (max-width: 500px) {
.navbar {
flex-direction: column;
align-items: center;
}
.links a {
margin: 5px;
}
}
✅ Write CSS for the following:
Q1. Create a flex container that wraps items on small screens.
Q2. Build a 3-column layout that becomes single-column on mobile.
Q3. Make flex items fill the width equally.
Q4. Add a gap between flex items.
Q5. Center items horizontally and vertically on all screens.
Q6. Change layout from row
to column
below 768px.
Q7. Make a responsive button group with Flexbox.
Q8. Adjust item sizes using flex-basis
and flex-grow
.
Q9. Create a sidebar that becomes top-bar on small screens.
Q10. Create a flex image gallery that stacks images on mobile.
Q1: Which property makes flex items wrap to the next line?
Q2: Which Flexbox property is most useful for mobile responsiveness?
Q3: What does flex: 1 1 200px; mean?
Q4: What helps apply different flex styles on small screens?
Q5: How to stack flex items vertically on mobile?
Q6: What does gap do in Flexbox?
Q7: What is a good flex-basis for equal-width cards?
Q8: Which layout will show horizontal on desktop and vertical on mobile?
Q9: How to prevent items from shrinking?
Q10: Which property combines grow, shrink, and basis?