Flexbox is a powerful layout system that makes it easy to design flexible responsive layouts.
Basic Flex Container
.container {
display: flex;
justify-content: space-between;
align-items: center;
gap: 1rem;
}
.item {
flex: 1; /* Equal width for all items */
padding: 1rem;
background: #f0f0f0;
}
Responsive Navigation
.navbar {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
align-items: center;
}
.nav-links {
display: flex;
gap: 2rem;
list-style: none;
}
@media (max-width: 768px) {
.navbar {
flex-direction: column;
}
.nav-links {
flex-direction: column;
width: 100%;
}
}
Centering Content
.center-box {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}