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 …


Ahmad Shadeed: Use Cases For CSS fit-content originally published on CSS-Tricks. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier

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;
}

To Shared LinkPermalink on CSS-Tricks


Ahmad Shadeed: Use Cases For CSS fit-content originally published on CSS-Tricks. You should get the newsletter.


This content originally appeared on CSS-Tricks and was authored by Chris Coyier


Print Share Comment Cite Upload Translate Updates
APA

Chris Coyier | Sciencx (2022-03-01T15:41:16+00:00) Ahmad Shadeed: Use Cases For CSS fit-content. Retrieved from https://www.scien.cx/2022/03/01/ahmad-shadeed-use-cases-for-css-fit-content/

MLA
" » Ahmad Shadeed: Use Cases For CSS fit-content." Chris Coyier | Sciencx - Tuesday March 1, 2022, https://www.scien.cx/2022/03/01/ahmad-shadeed-use-cases-for-css-fit-content/
HARVARD
Chris Coyier | Sciencx Tuesday March 1, 2022 » Ahmad Shadeed: Use Cases For CSS fit-content., viewed ,<https://www.scien.cx/2022/03/01/ahmad-shadeed-use-cases-for-css-fit-content/>
VANCOUVER
Chris Coyier | Sciencx - » Ahmad Shadeed: Use Cases For CSS fit-content. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2022/03/01/ahmad-shadeed-use-cases-for-css-fit-content/
CHICAGO
" » Ahmad Shadeed: Use Cases For CSS fit-content." Chris Coyier | Sciencx - Accessed . https://www.scien.cx/2022/03/01/ahmad-shadeed-use-cases-for-css-fit-content/
IEEE
" » Ahmad Shadeed: Use Cases For CSS fit-content." Chris Coyier | Sciencx [Online]. Available: https://www.scien.cx/2022/03/01/ahmad-shadeed-use-cases-for-css-fit-content/. [Accessed: ]
rf:citation
» Ahmad Shadeed: Use Cases For CSS fit-content | Chris Coyier | Sciencx | https://www.scien.cx/2022/03/01/ahmad-shadeed-use-cases-for-css-fit-content/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.