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...

You could also follow me on twitter. I have a couple of youtube channels if you want to see some video related content. RuneScape 3, Minecraft and also a coding channel here Web Dev.

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 important thing is not to stop questioning. Curiosity has its own reason for existence. One cannot help but be in awe when he contemplates the mysteries of eternity, of life, of the marvelous structure of reality. It is enough if one tries merely to comprehend a little of this mystery each day. Never lose a holy curiosity.


Albert Einstein
Random CSS Property

overflow-x

The overflow-x CSS property sets what shows when content overflows a block-level element's left and right edges. This may be nothing, a scroll bar, or the overflow content.
overflow-x css reference