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; }
ResultSpecifications
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
Posted in
12:22 am, February 22, 2022
Add Comment
Other Items in CSS
rgb()
rgba()
:right
right
@right-bottom
:root
rotate
rotate()
rotate3d()
rotateX()
rotateY()
rotateZ()
row-gap
ruby-align
ruby-position
saturate()
scale
scale()
scale3d()
scaleX()
scaleY()
scaleZ()
:scope
scroll-behavior
scroll-margin
scroll-margin-block
scroll-margin-block-end
scroll-margin-block-start
scroll-margin-bottom
scroll-margin-inline
scroll-margin-inline-end
scroll-margin-inline-start
scroll-margin-left
scroll-margin-right
scroll-margin-top
scroll-padding
scroll-padding-block
scroll-padding-block-end
scroll-padding-block-start
scroll-padding-bottom
scroll-padding-inline
scroll-padding-inline-end
scroll-padding-inline-start
scroll-padding-left
scroll-padding-right
scroll-padding-top
scroll-snap-align
scroll-snap-stop
scroll-snap-type
@scroll-timeline