Technology News

Ahmad Shadeed: Use Cases For CSS fit-content

Ahmad Shadeed covers the CSS fit-content sizing keyword. It’s useful! It just doesn’t come up super often. I find myself using min-content a lot more, like when setting up the height of a grid-template-row.

The fit-content keyword is actually closely related to min-content and max-content — it just has a little heuristic it follows that Ahmad nicely illustrates as a flow chart.

Ahmad Shadeed's flow chat illustrating the way browsers handle the CSS fit-content keyword.

“Use Cases For CSS fit-content” by Ahmad Shadeed

My favorite use case is covered here: sizing a <figure> with fit-content, so that it neatly wraps around the <img>. That way, even if the image doesn’t fill the parent space, and it can remain block-level.

We also covered PPK’s deep dive on fit-content last year. One of the key takeaways for understanding it is knowing that is it essentially a shorthand way of writing:

.box { width: fit-content; /* ... is the same as ... */ width: auto; min-width: min-content; max-width: max-content;
}

Direct Link →

A Comprehensive Guide to Building a Professional Business Website Using WordPress
CSS Custom Highlight API: The Future of Highlighting Text Ranges on the Web

Related Articles

Elon Musk is no free speech messiah

elon-musk-is-no-free-speech-messiah
A few days ago, Elon Musk asked his 81 million followers, “Is Twitter dying?” Musk calls himself a “free speech absolutist” — opposed to any restrictions on what someone can…

How to Create a Lifestyle Blog with WordPress

how-to-create-a-lifestyle-blog-with-wordpress
Undoubtedly, lifestyle and fashion bloggers require a blog that is visually appealing and stands out. Features, such as elegant galleries, beautiful typography, a lot of white space, and more, help…

New AI Agent Skill for WordPress

New AI Agent Skill for WordPress
Faster Way For AI Agents To Test AI code agents are getting better at writing WordPress plugins and themes, but testing can still be the slow part. WordPress contributor Brandon…

Using Automation to Increase Web Traffic

Exploring the Potential of the Metaverse: A New World Awaits
One of the biggest challenges entrepreneurs face is getting their business in front of potential customers. Marketing attracts leads, leads become customers, and customers provide profit. Unfortunately, outreach, networking, and…