47
loading...
This website collects cookies to deliver better user experience
min-content
— represents the minimum intrinsic size of an element. This means that when it's set as the width
(or inline-size
) of an element with text content, its size will be as long as the longest word. Every space or non-alphanumeric character (like hyphens, if hyphenation is auto
) can be used to apply a soft break, like in this example:max-content
– it works in the opposite way than min-content
since it represents the maximum intrinsic size of an element. width
(or inline-size
) of an element with text content, it will be as long as the content without any line breaks. If the size of the parent is narrower then the element will cause an overflow, as shown below:fit-content
— it works like a mix of min-content
and max-content
: an element sized with this keyword will stretch to contain the text but it won't be never longer than max-content
and never shorter than min-content
.fit-content
is not the same as auto
: an element with display: block;
and width: auto
will always take the entire space available while fit-content
size is limited by its content.calc()
expression, like inline-size: calc(min-content + 2rem)
.max-width/max-inline-size
, min-width/min-inline-size
or (in some browsers) flex-basis
.fit-content
can be somewhat useful.<br>
element before and no control over the markup: how could you show the link in a new line and centered?display: block
on the link of course, but this will naturally expand it taking the full width of the parent, so you need to also set a width
(or inline-size
) to limit its size.inline-size: fit-content
the content now dictates the size of the element itself