Let CSS figure out the layout

Kevin Powell on YouTubeWatch on YouTube

SaveMark complete

Sign in to save videos and track what you’ve finished.

IntermediateUI4 min

About this video

A short CSS tutorial showing how to build a layout that chooses its own number of columns based on how many child elements it contains, using :has(), :nth-child() and :last-child without extra classes or JavaScript. It also covers making the column count configurable and setting an upper limit with :not().

What you’ll learn

  • Count child elements in CSS using :has() and :nth-child()
  • Set a configurable column count for a grid layout
  • Cap the number of columns with :not()