Display & Flow
block, inline, inline-block, overflow
Skills taught: css.display, css.flow, css.overflow
Block vs inline
/* BLOCK — full width, stacks vertically, respects width/height/margin */
div, p, h1, section, article { display: block; } /* defaults */
/* INLINE — sits in text flow, width/height have NO effect */
span, a, strong, em { display: inline; } /* defaults */
/* INLINE-BLOCK — sits in text flow BUT respects width, height, padding */
.badge {
display: inline-block;
padding: 4px 10px;
border-radius: 999px;
background: #4fd1c5;
color: #0e1116;
font-size: 0.75rem;
font-weight: 700;
}
Showing and hiding elements
/* Removed from layout AND invisible */
.hidden { display: none; }
/* Invisible but STILL takes up space */
.invisible { visibility: hidden; }
/* Transparent but still interactive */
.transparent { opacity: 0; }
/* Visually hidden but accessible to screen readers */
.sr-only {
position: absolute;
width: 1px;
height: 1px;
padding: 0;
margin: -1px;
overflow: hidden;
clip: rect(0, 0, 0, 0);
white-space: nowrap;
border: 0;
}
Tip: The .sr-only pattern hides content visually while keeping it accessible to screen readers. Use it for skip links, icon button labels, and form hints.
Overflow
.box {
overflow: visible; /* default — content spills outside the box */
overflow: hidden; /* clips content to the box boundaries */
overflow: scroll; /* always shows scrollbars */
overflow: auto; /* scrollbars only when content overflows */
/* Axis-specific */
overflow-x: hidden;
overflow-y: auto;
}
Frequently Asked Questions
What replaced the float layout technique?
Flexbox and CSS Grid replaced float-based layouts. Floats are still valid for wrapping text around images (their original purpose), but should not be used for page layout.
What is display: contents?
display: contents makes the element itself invisible (no box is generated) but its children participate in the parent's layout as if the element didn't exist. Useful for wrapper divs in flexbox/grid.