Phase 3 — Layout
#9 Display and positioning
display, position, z-index, float
The display property
The display property controls how an element participates in layout:
Display values
/* Block: takes full width, starts on new line */
div, p, h1, section { display: block; }
/* Inline: flows with text, no width/height */
span, a, strong { display: inline; }
/* Inline-block: inline + allows width/height */
.badge {
display: inline-block;
padding: 4px 8px;
border-radius: 4px;
}
/* None: completely hidden */
.hidden { display: none; }Positioning
Position values
/* Relative: offset from normal position */
.tooltip-trigger {
position: relative;
}
/* Absolute: positioned relative to nearest positioned ancestor */
.tooltip {
position: absolute;
top: 100%;
left: 50%;
transform: translateX(-50%);
}
/* Fixed: stays in place during scroll */
.navbar {
position: fixed;
top: 0;
left: 0;
width: 100%;
z-index: 100;
}
/* Sticky: sticks when scrolled past */
.table-header {
position: sticky;
top: 0;
background: white;
}Stacking context (z-index)
z-index controls which elements appear on top when they overlap. It only works on positioned elements (not static):
z-index
.overlay {
position: fixed;
inset: 0; /* top/right/bottom/left: 0 */
background: rgba(0,0,0,0.5);
z-index: 50;
}
.modal {
position: fixed;
z-index: 51; /* Above overlay */
}Your turn
Try the display and positioning commands below:
terminal — browser