fit-content
Quick Summary for fit-content()
The fit-content behaves as fit-content(stretch). In practice this means that the box will use the available space, but never more than max-content.
Code Usage for fit-content()
width: fit-content block-size: fit-content 
More Details for fit-content()

fit-content

The fit-content behaves as fit-content(stretch). In practice this means that the box will use the available space, but never more than max-content.

When used as laid out box size for width, height, min-width, min-height, max-width and max-height the maximum and minimum sizes refer to the content size.

Note: The CSS Sizing specification also defines the fit-content() function. This page details the keyword.

Syntax

width: fit-content block-size: fit-content 

Examples

Using fit-content for box sizing

HTML
<div class="container">   <div class="item">Item</div>   <div class="item">Item with more text in it.</div>   <div class="item">Item with more text in it, hopefully we have added enough text so the text will start to wrap.</div> </div> 
CSS
.container {   border: 2px solid #ccc;   padding: 10px;   width: 20em; }  .item {   width: -moz-fit-content;   width: fit-content;   background-color: #8ca0ff;   padding: 5px;   margin-bottom: 1em; } 
Result

Specifications

Specification
CSS Box Sizing Module Level 4 # valdef-width-fit-content

Supported for width (and other sizing properties)

See also

Related sizing keywords: min-content, max-content Select your preferred language English (US)EspañolFrançais日本語中文 (简体) Change language

No Items Found.

Add Comment
Type in a Nick Name here
 
Other Categories in CSS
css
Search CSS
Search CSS by entering your search text above.
Welcome

This is my test area for webdev. I keep a collection of code here, mostly for my reference. Also if i find a good link, i usually add it here and then forget about it. more...

Subscribe to weekly updates about things i have added to the site or thought interesting during the last week.

You could also follow me on twitter or not... does anyone even use twitter anymore?

If you found something useful or like my work, you can buy me a coffee here. Mmm Coffee. ☕

❤️👩‍💻🎮

🪦 2000 - 16 Oct 2022 - Boots
Random Quote
The problem with hoarding is you end up living off your reserves. Eventually, you’ll become stale. If you give away everything you have, you are left with nothing. This forces you to look, to be aware, to replenish. . . . Somehow the more you give away, the more comes back to you.
Paul Arden
Random CSS Property

revert

The revert CSS keyword reverts the cascaded value of the property from its current value to the value the property would have had if no changes had been made by the current style origin to the current element. Thus, it resets the property to its inherited value if it inherits from its parent or to the default value established by the user agent's stylesheet (or by user styles, if any exist). It can be applied to any CSS property, including the CSS shorthand all.
revert css reference