logical: block-size
, inline-size
, see Writing Mode
- depends on layout properties
max-content
for ODT inline
, float, absolutely / fixedly positioned element, flex / grid container, etc.
stretch
for ODT block
- intrinsic size for replaced elements, e.g. images
- beware: always specify maximum size for replaced elements, otherwise may overflow, e.g. images ❗️
- beware:
max-content
is zero for empty element, needs to explicitly set value, e.g. float, absolutely / fixedly positioned element, etc. ❗️
- adapts to content (or context in Block Layout of Flow Layout)
<length-percentage>
- size of sizing box, see Sizing box
- beware: by default sizing box is content box ❗️
- percentage relative to size in same direction of containing block
- adapts to nothing (only percentage adapts to context)
- beware: don’t set absolute size since doesn’t adapt to content or context, facilitates overflow ❗️
min-content
- minimum size of content box such that contents don’t overflow
- adapts to content, i.e. zero if empty element ❗️
max-content
- minimum size of content box such that contents don’t overflow given infinite available space
- can think of as “ideal” preferred size
- beware:
min-content
≤ max-content
❗️
- adapts to content, i.e. zero if empty element ❗️
stretch
- maximum size of margin box in available space
- beware:
stretch
is not constrained by min-
/max-content
, i.e. stretch
can be smaller than both ❗️
- adapts to context
fit-content
min(max-content, max(min-content, stretch))
- adapts to content and context
Sizing box
- sub-box to which sizing properties refer when sizing value is of
<length-percentage>
- controlled by
box-sizing
property
- beware: property name should have been
sizing-box
❗️
- not inherited
- values:
content-box
, border-box
- initial value:
content-box
- beware: initial value should have been
border-box
since total size of box ❗️
- beware: no
padding-box
value because of little use ❗️
- beware: no
margin-box
value because margin not part of box, see Margin ❗️
- beware: doesn’t set sub-box for non-
<length-percentage>
sizing values, e.g. min-content
, max-content
, etc. ❗️
- beware: by default needs to add padding and border to
<length-percentage>
to get total size of box ❗️
- beware: by default box overflows if has
100%
size and non-zero padding or border (or margin), since size applies to content box ❗️
- beware: size of padding, border and margin area takes precedence over size of (sizing) box, i.e. if area of sub-boxes within (sizing) box is bigger than size of (sizing) box, then size of content box is set to zero and size of (sizing) box becomes as large as necessary to fit area of sub-boxes ⚠️
<div></div>
div {
box-sizing: border-box;
width: 100px;
padding: 0 30px;
border-width: 0 40px;
height: 1rem;
background-color: lightgrey;
border-style: solid;
border-color: red
}
Resources