Sizing to the content in CSS
Three keywords that ask the content how wide it wants to be.
.tag { inline-size: max-content; padding-inline: 0.6em; }
.label-column {
inline-size: min-content;
overflow-wrap: break-word;
}
.drawer {
inline-size: fit-content;
max-inline-size: 24rem;
min-inline-size: 12rem;
}
.split {
display: grid;
grid-template-columns: fit-content(20rem) 1fr;
gap: 1.5rem;
}
How it works
min-contentis the widest unbreakable word.max-contentis the whole thing on one line, however long that is.fit-contentsizes to the content between those two bounds.- The functional
fit-content(20rem)is a grid track size, not a width.
Keywords and builtins used here
displaydraweremgapgridremsplittag
The run, in numbers
- Lines
- 18
- Characters to type
- 303
- Tokens
- 66
- Three-star pace
- 85 tpm
At the three-star pace of 85 tokens a minute, this run takes about 47 seconds.
Step 1 of 3 in Sizing, step 14 of 24 in Flexbox & grid.