Position & overflow
Pin things (sticky top-0), place them on a corner (absolute top-2 end-2), stack them (z-10), and decide what happens when content doesn't fit.
On a corner
New
Team plan
Up to 20 people
<div class="relative box p-6 max-w-sm">
<span class="badge badge-yellow absolute top-2 end-2">New</span>
<b class="block">Team plan</b>
<span class="text-sm text-muted">Up to 20 people</span>
</div>Stuck while scrolling
sticky top-0
Scroll this box: the header stays at the top.
Monday: planning
Tuesday: design review
Wednesday: build
Thursday: test
Friday: ship
<div class="box h-48 overflow-y-auto p-0">
<div class="sticky top-0 bg-surface border-b px-4 py-2 font-semibold z-10">sticky top-0</div>
<div class="p-4 space-y-3 text-sm">
<p>Scroll this box: the header stays at the top.</p><p>Monday: planning</p><p>Tuesday: design review</p><p>Wednesday: build</p><p>Thursday: test</p><p>Friday: ship</p>
</div>
</div>Pictures in a fixed shape
aspect-video keeps 16:9, object-cover fills the shape without stretching.
aspect-video
aspect-square
<div class="aspect-video w-64 bg-cyan rounded-lg grid place-items-center">aspect-video</div>
<div class="aspect-square w-32 bg-pink rounded-lg grid place-items-center">aspect-square</div>Position
| Class | CSS |
|---|---|
static | position: static; |
relative | position: relative; |
absolute | position: absolute; |
fixed | position: fixed; |
sticky | position: sticky; |
z-0 | z-index: 0; |
z-10 | z-index: 10; |
z-20 | z-index: 20; |
z-30 | z-index: 30; |
z-40 | z-index: 40; |
z-50 | z-index: 50; |
z-auto | z-index: auto; |
Placement
s and e mean start and end: left and right in English, swapped in right-to-left languages.
| Class | CSS |
|---|---|
inset-0 | inset: 0; |
inset-x-0 | inset-inline: 0; |
inset-y-0 | inset-block: 0; |
top-0 | top: 0; |
bottom-0 | bottom: 0; |
start-0 | inset-inline-start: 0; |
end-0 | inset-inline-end: 0; |
inset-1 | inset: .25rem; |
inset-x-1 | inset-inline: .25rem; |
inset-y-1 | inset-block: .25rem; |
top-1 | top: .25rem; |
bottom-1 | bottom: .25rem; |
start-1 | inset-inline-start: .25rem; |
end-1 | inset-inline-end: .25rem; |
inset-2 | inset: .5rem; |
inset-x-2 | inset-inline: .5rem; |
inset-y-2 | inset-block: .5rem; |
top-2 | top: .5rem; |
bottom-2 | bottom: .5rem; |
start-2 | inset-inline-start: .5rem; |
end-2 | inset-inline-end: .5rem; |
inset-3 | inset: .75rem; |
inset-x-3 | inset-inline: .75rem; |
inset-y-3 | inset-block: .75rem; |
top-3 | top: .75rem; |
bottom-3 | bottom: .75rem; |
start-3 | inset-inline-start: .75rem; |
end-3 | inset-inline-end: .75rem; |
inset-4 | inset: 1rem; |
inset-x-4 | inset-inline: 1rem; |
inset-y-4 | inset-block: 1rem; |
top-4 | top: 1rem; |
bottom-4 | bottom: 1rem; |
start-4 | inset-inline-start: 1rem; |
end-4 | inset-inline-end: 1rem; |
inset-6 | inset: 1.5rem; |
inset-x-6 | inset-inline: 1.5rem; |
inset-y-6 | inset-block: 1.5rem; |
top-6 | top: 1.5rem; |
bottom-6 | bottom: 1.5rem; |
start-6 | inset-inline-start: 1.5rem; |
end-6 | inset-inline-end: 1.5rem; |
inset-8 | inset: 2rem; |
inset-x-8 | inset-inline: 2rem; |
inset-y-8 | inset-block: 2rem; |
top-8 | top: 2rem; |
bottom-8 | bottom: 2rem; |
start-8 | inset-inline-start: 2rem; |
end-8 | inset-inline-end: 2rem; |
inset-full | inset: 100%; |
inset-x-full | inset-inline: 100%; |
inset-y-full | inset-block: 100%; |
top-full | top: 100%; |
bottom-full | bottom: 100%; |
start-full | inset-inline-start: 100%; |
end-full | inset-inline-end: 100%; |
inset-1/2 | inset: 50%; |
inset-x-1/2 | inset-inline: 50%; |
inset-y-1/2 | inset-block: 50%; |
top-1/2 | top: 50%; |
bottom-1/2 | bottom: 50%; |
start-1/2 | inset-inline-start: 50%; |
end-1/2 | inset-inline-end: 50%; |
inset-auto | inset: auto; |
inset-x-auto | inset-inline: auto; |
inset-y-auto | inset-block: auto; |
top-auto | top: auto; |
bottom-auto | bottom: auto; |
start-auto | inset-inline-start: auto; |
end-auto | inset-inline-end: auto; |
Overflow
A scrolling box (overflow-y-auto) gets Momo's thin scrollbar. overscroll-contain stops a scroll inside it from moving the page.
| Class | CSS |
|---|---|
overflow-auto | overflow: auto; |
overflow-x-auto | overflow-x: auto; |
overflow-y-auto | overflow-y: auto; |
overflow-hidden | overflow: hidden; |
overflow-x-hidden | overflow-x: hidden; |
overflow-y-hidden | overflow-y: hidden; |
overflow-clip | overflow: clip; |
overflow-x-clip | overflow-x: clip; |
overflow-y-clip | overflow-y: clip; |
overflow-visible | overflow: visible; |
overflow-x-visible | overflow-x: visible; |
overflow-y-visible | overflow-y: visible; |
overflow-scroll | overflow: scroll; |
overflow-x-scroll | overflow-x: scroll; |
overflow-y-scroll | overflow-y: scroll; |
overscroll-auto | overscroll-behavior: auto; |
overscroll-contain | overscroll-behavior: contain; |
overscroll-none | overscroll-behavior: none; |
visible | visibility: visible; |
invisible | visibility: hidden; |
float-start | float: inline-start; |
float-end | float: inline-end; |
float-none | float: none; |
Floats (float-start, float-end) are for text flowing around a picture. Put .clearfix on the parent so it grows around its floated children.
Pictures and video
| Class | CSS |
|---|---|
aspect-auto | aspect-ratio: auto; |
aspect-square | aspect-ratio: 1 / 1; |
aspect-video | aspect-ratio: 16 / 9; |
aspect-4/3 | aspect-ratio: 4 / 3; |
aspect-3/2 | aspect-ratio: 3 / 2; |
aspect-21/9 | aspect-ratio: 21 / 9; |
aspect-3/4 | aspect-ratio: 3 / 4; |
aspect-9/16 | aspect-ratio: 9 / 16; |
object-contain | object-fit: contain; |
object-cover | object-fit: cover; |
object-fill | object-fit: fill; |
object-none | object-fit: none; |
object-scale-down | object-fit: scale-down; |
object-center | object-position: center; |
object-top | object-position: top; |
object-bottom | object-position: bottom; |
object-start | object-position: left; |
object-end | object-position: right; |