On this page10 sections
Lecture 045: Multiple Columns & User Interface
| Category | 7: Advanced Styling |
| Lecture | 045 of 057 |
| Estimated video length | 10 min |
| Target | CSS3 · any modern browser |
| Level | Intermediate |
Multi-column layout flows text into newspaper-style columns automatically. The user-interface properties control how people interact with elements: resizing boxes, the cursor shape, text selection, scrolling behaviour and even the caret colour.
Learning Objectives
- Split text into columns with
column-countandcolumn-width - Style the gap and dividing line, and make headings span all columns
- Use
resize,cursor,user-select,caret-colorandpointer-events - Control scrolling with
scroll-behaviorandscroll-snap
1. Columns
Example: drag the preview corner:
<style>
.news { column-count: 3; column-gap: 28px; column-rule: 1px solid #dee2e6; font: 14px/1.6 Georgia, serif; }
.news h3 { column-span: all; margin: 0 0 10px; font-family: system-ui; }
</style>
<div class="news">
<h3>Spring arrives in Hunza</h3>
<p>The apricot trees of Hunza burst into blossom every spring, painting the valley in pink and white. Visitors come from across the country to walk the terraced orchards.</p>
<p>Local families have tended these trees for generations, drying the fruit in the summer sun on flat rooftops. Dried apricots are sold in markets all year round.</p>
<p>The best time to visit is early April, when the snow-capped peaks still frame the blossoms and the days are cool and clear.</p>
</div>| Property | Does |
|---|---|
column-count: 3 | Exactly three columns |
column-width: 200px | As many columns as fit, each at least 200px wide (responsive) |
column-gap | Space between columns |
column-rule | A dividing line (like a border) |
column-span: all | An element (a heading) stretches across every column |
columns: 200px 3 sets "at least 200px, at most three columns" in one line.
2. resize
Example: drag the bottom-right corners:
<div style="resize: both; overflow: auto; width: 200px; height: 80px; border: 2px dashed #74c0fc; padding: 8px;">resize: both</div>
<br>
<textarea style="resize: vertical; width: 260px;">Textareas can be limited to vertical resizing.</textarea>resize only works when overflow is not visible.
3. cursor
Example: hover over each box:
<style>
span { display: inline-block; padding: 8px 10px; margin: 3px; background: #f1f3f5; border-radius: 6px; font: 13px monospace; }
</style>
<span style="cursor: pointer;">pointer</span>
<span style="cursor: not-allowed;">not-allowed</span>
<span style="cursor: help;">help</span>
<span style="cursor: wait;">wait</span>
<span style="cursor: move;">move</span>
<span style="cursor: grab;">grab</span>
<span style="cursor: text;">text</span>
<span style="cursor: zoom-in;">zoom-in</span>
<span style="cursor: crosshair;">crosshair</span>4. Selection, Caret and Pointer Events
Example
<p style="user-select: none; background: #fff3bf; padding: 6px;">user-select: none (try to select this)</p>
<p style="user-select: all; background: #d3f9d8; padding: 6px;">user-select: all: one click selects everything, e.g. a code to copy</p>
<input placeholder="caret-color: red" style="caret-color: #e03131; padding: 8px;">
<p><a href="#" style="pointer-events: none; color: #adb5bd;">pointer-events: none (this link can't be clicked)</a></p>
<style> ::selection { background: #b197fc; color: white; } </style>accent-color (Lecture 024) recolours checkboxes, radios and sliders.
5. Smooth Scrolling and Scroll Snap
Example: swipe or scroll the row; each card snaps into place:
<style>
.row { display: flex; gap: 10px; overflow-x: auto; scroll-snap-type: x mandatory; padding-bottom: 8px; }
.row div { flex: 0 0 70%; height: 100px; scroll-snap-align: center; border-radius: 10px; display: grid; place-items: center; color: white; font: 600 20px system-ui; }
</style>
<div class="row">
<div style="background: #1971c2;">1</div><div style="background: #2f9e44;">2</div><div style="background: #e8590c;">3</div><div style="background: #7048e8;">4</div>
</div>html { scroll-behavior: smooth; } /* #anchor links glide instead of jumping */Common Beginner Mistakes
1. Long paragraphs in narrow columns on phones. Use column-width, not a fixed column-count.
2. resize without overflow. It won't work while overflow is visible.
3. user-select: none on normal text. Visitors expect to be able to copy text.
4. pointer-events: none as a security measure. It only stops the mouse; keyboard users can still reach the element.
Practice Questions
- Split a paragraph into two columns with a 30px gap.
- How do you make a heading stretch across all columns?
- Which value of
resizeallows only up-and-down resizing? - Which cursor suggests that something can't be clicked?
- How do you make anchor links scroll smoothly?
- Which two properties make a carousel snap to each card?
Practice Answers
p { column-count: 2; column-gap: 30px; }column-span: all;resize: vertical;cursor: not-allowed;html { scroll-behavior: smooth; }scroll-snap-typeon the container andscroll-snap-alignon the items.
Key Takeaways
column-count/column-width,column-gap,column-ruleandcolumn-spanmake newspaper columns.resize,cursor,user-select,caret-colorandpointer-eventsshape interaction.scroll-behavior: smoothand scroll snap make scrolling feel polished.