-
Hajipur, Bihar, 844101
A Flex Container is the parent element in a flexbox layout that holds flex items. By setting display: flex
or display: inline-flex
on an element, it becomes a flex container, and its direct children automatically become flex items.
The flex container controls the flow, direction, alignment, spacing, and wrapping of the items inside it.
.container {
display: flex; /* or inline-flex */
}
<div class="container">
<div>Item 1</div>
<div>Item 2</div>
<div>Item 3</div>
</div>
Property | Description |
---|---|
display |
Defines flex behavior: flex or inline-flex |
flex-direction |
Sets the direction of items (row, column, etc.) |
flex-wrap |
Controls whether items wrap or stay in one line |
flex-flow |
Shorthand for flex-direction and flex-wrap |
justify-content |
Aligns items horizontally within the container |
align-items |
Aligns items vertically within the container |
align-content |
Aligns multi-line rows (used with wrapping) |
.container {
display: flex;
justify-content: center;
align-items: center;
height: 200px;
background-color: #f2f2f2;
}
/* Horizontal */
.container {
display: flex;
flex-direction: row;
}
/* Vertical */
.container {
display: flex;
flex-direction: column;
}
.container {
display: flex;
flex-wrap: wrap;
}
✅ Write CSS for the following:
Q1. Create a flex container with horizontal layout.
Q2. Create a flex container with vertical layout.
Q3. Make a container that allows its items to wrap.
Q4. Center items in the middle of the container.
Q5. Align items to the bottom using align-items
.
Q6. Space items equally using justify-content
.
Q7. Reverse the order of items.
Q8. Create a container using inline-flex
.
Q9. Set different wrap and direction using flex-flow
.
Q10. Add spacing between rows using align-content
.
Q1: What CSS property makes an element a flex container?
Q2: Which direction is default in a flex container?
Q3: Which property wraps flex items onto multiple lines?
Q4: What does justify-content: space-between; do?
Q5: Which shorthand combines direction and wrapping?
Q6: Which property aligns items vertically in a single line?
Q7: What value makes a flex container layout vertically?
Q8: What does inline-flex do?
Q9: What does align-content affect?
Q10: Which value reverses item direction in a flex container?