0
0
SASSmarkup~10 mins

Flexbox utility class generation in SASS - Browser Rendering Trace

Choose your learning style9 modes available
Render Flow - Flexbox utility class generation
Read SASS variables and mixins
Generate CSS classes for flexbox
Compile CSS output
Browser loads CSS
Apply flexbox styles to elements
Render flex container and items
The SASS code defines variables and mixins that create multiple CSS utility classes for flexbox. When compiled, the browser reads these classes and applies flexbox layout styles to elements, rendering them accordingly.
Render Steps - 4 Steps
Code Added:<div class="flex-row justify-center items-center"> ... </div>
Before
[ ]
(empty page)
After
[flex container]
[ ] [ ] [ ]
(Box 1, Box 2, Box 3 horizontally aligned)
Adding the flex container with utility classes sets display:flex and centers items horizontally and vertically.
🔧 Browser Action:Creates flex formatting context, triggers layout reflow
Code Sample
This SASS code generates utility classes for flexbox directions, justification, and alignment. The HTML uses these classes to create a flex container with centered items visually arranged in a row.
SASS
<div class="flex-row justify-center items-center">
  <div class="box">Box 1</div>
  <div class="box">Box 2</div>
  <div class="box">Box 3</div>
</div>
SASS
$directions: (row, column);
$justify: (start, center, end, between, around);
$align: (start, center, end, stretch);

@each $dir in $directions {
  .flex-#{$dir} {
    display: flex;
    flex-direction: $dir;
  }
}

@each $j in $justify {
  .justify-#{$j} {
    justify-content: map-get((start: flex-start, center: center, end: flex-end, between: space-between, around: space-around), $j);
  }
}

@each $a in $align {
  .items-#{$a} {
    align-items: map-get((start: flex-start, center: center, end: flex-end, stretch: stretch), $a);
  }
}

.box {
  width: 5rem;
  height: 5rem;
  background: #4a90e2;
  color: white;
  display: flex;
  justify-content: center;
  align-items: center;
  margin: 0.5rem;
  border-radius: 0.5rem;
}
Render Quiz - 3 Questions
Test your understanding
After applying step 3 (.justify-center), how are the flex items arranged horizontally?
AAll items are centered horizontally in the container
BItems are aligned to the left edge
CItems are spaced evenly with space between
DItems are aligned to the right edge
Common Confusions - 3 Topics
Why don't my flex items center vertically when I use justify-content:center?
Justify-content aligns items along the main axis (usually horizontal). To center vertically, use align-items:center which aligns along the cross axis.
💡 Main axis uses justify-content; cross axis uses align-items (see render_steps 3 and 4).
Why does adding display:flex change the layout completely?
display:flex creates a flex container that changes how child elements are laid out from block or inline to flexible boxes.
💡 Adding display:flex triggers a new layout mode (render_step 1).
Why do my boxes not stretch to fill container height?
By default, align-items is stretch, but if you set align-items:center, items keep their height and center vertically instead of stretching.
💡 align-items controls vertical size behavior (render_step 4).
Property Reference
PropertyValue AppliedAxis/DirectionVisual EffectCommon Use
displayflexN/ACreates flex container, enables flex layoutStart flexbox layout
flex-directionrow / columnMain axisSets direction of flex items (horizontal or vertical)Layout orientation
justify-contentflex-start / center / flex-end / space-between / space-aroundMain axisAligns items horizontally or vertically along main axisControl item distribution
align-itemsflex-start / center / flex-end / stretchCross axisAligns items vertically or horizontally along cross axisControl item alignment
width / heightfixed sizesN/ASets size of flex itemsControl box dimensions
Concept Snapshot
Flexbox utility classes use SASS loops to generate CSS for flex-direction, justify-content, and align-items. Display:flex creates a flex container. Justify-content aligns items along the main axis (horizontal by default). Align-items aligns items along the cross axis (vertical by default). Utility classes let you quickly apply common flexbox layouts. Boxes inside flex containers respond visually to these properties.