Collective #719





Preline

Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.

Check it out





Bun

Bun is a new JavaScript runtime with a native bundler, transpiler, task runner and npm client built-in.

Check it out







Felt

Felt brings the simple elegance of modern creative software to the world of maps.

Check it out



Masonry? In CSS?!

Michelle Barker explains the current approach for creating a Masonry layout and what the downsides are.

Read it







Adobe X Bowie

Step into Bowie’s virtual dressing room. An amazing gaming project made by Bruno Arizio and Resn for Adobe

Check it out






The post Collective #719 appeared first on Codrops.

Centering a div That Maintains Aspect-Ratio When There’s Body Margin

Andrew Welch had a little CSS challenge the other day to make an ordinary div:

• centered vertically + horizontally
• scales to fit the viewport w/ a margin around it
• maintains an arbitrary aspect ratio
• No JS

There's a video in that tweet if it helps you visualize the challenge. I saw Paul Bakaus blogging about this the other day, too, so it's a thing that comes up!

Mark Huot got fancy applying aspect ratios directly with width/height and creating the margins from subtracting from those dimensions:

Amelia Wattenberger's idea is to set both height/width and max-height/max-width with viewport units, and center it with the classic translate trick:

Eric A. Meyer did the same, only centered with flexbox instead.

Brian Hart used vmin units for the aspect ratio sizing and centered it with flexbox:

Benoît Rouleau did the same but used calc() for the margins in a different unit.

Andrew really likes Jonathan Melville's approach. Most of it is in Tailwind classes so it's a smidge hard for me to understand as I'm not used to looking at code like that yet.

Andrew said he ultimately went with the vmin thing — although I see he's using calc() to subtract vmin units from each other which isn't really necessary unless, I guess, you wanna see the math.

The post Centering a div That Maintains Aspect-Ratio When There’s Body Margin appeared first on CSS-Tricks.