Display & Positioning
display
| Value | Behaviour |
|---|---|
block | full width, starts on a new line (div, p, h1) |
inline | flows inside text; width and height are ignored (span, a) |
inline-block | flows inline but respects width, height and padding |
flex / grid | modern layout containers (next module) |
none | hidden and takes no space |
visibility: hidden hides an element but keeps its space.
position
| Value | How it moves |
|---|---|
static | normal flow (default) |
relative | nudged from its normal spot; becomes the anchor for absolute children |
absolute | placed relative to the nearest positioned ancestor; leaves the flow |
fixed | stuck to the screen while scrolling (chat buttons) |
sticky | scrolls normally, then sticks (top: 0) at a point (table headers, nav bars) |
Use top, right, bottom and left to place positioned elements, and z-index for which is on top (it only works on positioned or flex/grid items).
Common pattern: a badge on a card
Make the parent position: relative and the badge position: absolute; top: 8px; right: 8px;.
Overflow
overflow: hidden | auto | scroll. Use auto for scrollable areas, and text-overflow: ellipsis with white-space: nowrap for "…".
Example
<style>
body { font-family: sans-serif; height: 1200px; }
.nav {
position: sticky; top: 0;
background: #111827; color: white; padding: 12px;
}
.card {
position: relative;
width: 220px; margin: 24px; padding: 20px;
border: 1px solid #ddd; border-radius: 12px;
}
.badge {
position: absolute; top: -10px; right: -10px;
background: crimson; color: white;
border-radius: 999px; padding: 4px 10px; font-size: 12px;
}
.fab {
position: fixed; right: 20px; bottom: 20px;
background: #6366f1; color: white;
border-radius: 50%; width: 56px; height: 56px;
display: grid; place-items: center; font-size: 24px;
}
</style>
<div class="nav">Sticky navigation (scroll down)</div>
<div class="card">Product card <span class="badge">SALE</span></div>
<div class="fab">+</div>