-
Hajipur, Bihar, 844101
Flex Items are the direct children of a flex container. When an element is declared as display: flex
, all its immediate child elements become flex items, which can then be controlled using various Flexbox properties to adjust their size, position, and alignment inside the container.
Property | Description |
---|---|
order |
Controls the order in which items appear |
flex-grow |
Defines how much an item will grow relative to others |
flex-shrink |
Defines how much an item will shrink relative to others |
flex-basis |
Sets the initial main size of the item before space is distributed |
flex |
Shorthand for flex-grow , flex-shrink , and flex-basis |
align-self |
Allows individual alignment overriding align-items from the container |
<div class="container">
<div class="item">1</div>
<div class="item">2</div>
<div class="item">3</div>
</div>
.container {
display: flex;
}
.item {
flex: 1;
}
This divides all items equally within the container.
order
to Rearrange Items.item:nth-child(3) {
order: -1;
}
This moves the third item to the beginning.
flex-grow
, flex-shrink
, flex-basis
.item1 {
flex-grow: 2;
}
.item2 {
flex-grow: 1;
}
Item 1 will take twice the space of item 2.
.item3 {
flex: 1 0 200px; /* grow, shrink, basis */
}
align-self
.item {
align-self: flex-end;
}
This overrides the vertical alignment for just this item.
✅ Write CSS for the following:
Q1. Make all flex items take equal space.
Q2. Make one item grow twice as much as others.
Q3. Shrink one item faster than others on small screens.
Q4. Set a fixed initial width using flex-basis
.
Q5. Use shorthand flex: 1 0 100px
.
Q6. Change the order of one item to come first.
Q7. Align one item to the top while others remain centered.
Q8. Prevent one item from shrinking.
Q9. Make the first item grow and the last shrink.
Q10. Remove alignment from one item using align-self: auto
.
Q1: What makes a child element a flex item?
Q2: Which property changes the order of a flex item?
Q3: What does flex-grow: 2; mean?
Q4: What does flex: 1; shorthand represent?
Q5: Which property prevents an item from shrinking?
Q6: What does flex-basis control?
Q7: Which property aligns a specific item differently from others?
Q8: What is the default value of order?
Q9: What happens when multiple items have different flex-grow values?
Q10: Which value of align-self stretches the item to full height?