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 happiest People don't have the best of everything, they just make the best of everything.
Unknown
Random CSS Property

overflow-inline

The overflow-inline CSS property sets what shows when content overflows the inline start and end edges of a box. This may be nothing, a scroll bar, or the overflow content.
overflow-inline css reference