</> Code Corner

CSS · CSS Flexbox · Lesson 61

CSS Flex Items

order, flex-grow, flex-shrink, flex-basis and align-self.

Direct children of a flex container have their own properties.

Example

<style>
.c { display: flex; background: #1e90ff; padding: 6px; height: 140px; }
.c div { background: #f1f1f1; margin: 6px; padding: 12px; text-align: center; }
.a { flex-grow: 1; }
.b { flex-grow: 3; }
.d { order: -1; background: gold !important; }
.e { align-self: flex-end; }
</style>
<div class="c">
  <div class="a">grow 1</div>
  <div class="b">grow 3</div>
  <div class="d">order -1</div>
  <div class="e">align-self end</div>
</div>
Property Use
order Visual order of the item (default 0)
flex-grow How much the item grows relative to others
flex-shrink How much the item shrinks
flex-basis Initial size before growing/shrinking
flex Shorthand: grow shrink basis
align-self Overrides align-items for one item

Keep reading “CSS Flex Items”

Sign up to read the full lesson, try every example in the live editor, and take the 5-question quiz.

Chat with us 👋