CSS Layout Patterns #7

nidhinkumarnidhinkumar
2 min read

If you don’t have time to read but want to know what’s there in this post. Find the quick read 👇

Quick Read

On this Series

We are going to look at the commonly used CSS layout patterns. Most of the patterns which we are going to see use CSS grid and flexbox to achieve the common UI patterns such as cards, dynamic grid areas, and full-page layouts supported on all modern browsers.

The patterns which we are going to see in this series are

  1. Aspect ratio Image Card

  2. Clamping Card

  3. Deconstructed Pancake

  4. Holy grail layout

  5. Line up

  6. Pancake Stack

  7. RAM (Repeat, Auto, Minmax)

  8. Sidebar says something

  9. Super centered

  10. 12-span grid

  11. Autobot

  12. Container query card

  13. Content center

  14. Fluffy center

  15. Gentle flex

  16. Pop n’ Plop

If you are new to this series check out the Part 6👇

Scan the QR Code to Read more :)

On this Post

In this post, we are going to see the following patterns that are

  1. Content center

  2. Fluffy center

1. Content center

A centering technique that is only a few lines of CSS, works great for many elements but has the side effect of making children match the width of the widest element.

It can be used in the grid as well as in flex since it centers and justifies children collectively, it’s a solid centering technique for groups of elements meant to be read.

.content-center {
  display: grid;
  place-content: center;
  gap: 1ch;
}
  • Content is centred even under constrained space and overflow

  • Centering edits and maintenance are all in one spot

  • Gap guarantees equal spacing among n children

  • Grid creates rows by default

Content Center Demo

Content centers are great for macro layouts containing paragraphs and headlines, prototypes, or generally things that need legible centering.

2. Fluffy Center

A centering technique that puts the content in the center via equal padding around all its sides.

It is the only centering technique that’s entirely element/child owned.

Fluffy Center Demo

  • Protects content

  • Every test is secretly containing this centering strategy

  • Word space is gap

  • There’s a clash between the container and the items, naturally since each are being very firm about their sizing

Fluffy center are great for word or phrase-centric centering, tags, pills, buttons, chips, and more.

Congratulations!!!

End Note

0
Subscribe to my newsletter

Read articles from nidhinkumar directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

nidhinkumar
nidhinkumar