CSS = Cascading Style Sheets. HTML says what something is; CSS says how it looks โ colors, spacing, borders, layout.
CSS goes in its own file (e.g. style.css). Each HTML page opts in with one line
inside <head>:
<link rel="stylesheet" href="style.css">
<h1> color appeared on both index and members pages at once.
property: value; line changes one thing.margin-bottum) is silently ignored.
| Selector | Targets | Example |
|---|---|---|
h1 | Every tag of that type | all headings |
.low-stock | Anything with class="low-stock" (note the dot) | just the rows you tagged |
th, td | Both, at once (comma = "and") | header + data cells |
nav a | An <a> inside a <nav> (space = "descendant") | only navbar links |
a { color: white; } โ which hits every
link on the site, a trap waiting to make some future link invisible. The fix was the descendant
selector nav a { color: white; } so only navbar links change. Prefer the
narrowest selector that does the job.
Every element is a box with four layers. This is the single most important idea in CSS layout.
| Property | Where | Effect |
|---|---|---|
padding | Inside the border | Breathing room around content (your table cells) |
border | The wall | 1px solid black = thickness, style, color |
margin | Outside the border | Pushes other elements away |
Boxes come in two default behaviors โ this explains a lot of "why won't it move?" moments.
Switch between them with display: block; or display: inline;. That's how you
turned form labels into stacked rows (label { display: block; }) and retired the
<br> hack.
margin-bottom on an inline element does nothing. Inline boxes have no
vertical box to push from โ top/bottom margin is ignored (left/right still work). Fixes:
put the margin on a block element instead, or use display: inline-block;
(flows inline, but gains a real box that respects vertical margin).
Set display: flex; on a parent and its direct children line up in a
row. It's a conversation: the switch goes on the parent, the children fall into line.
nav {
display: flex;
gap: 20px;
background-color: darkslateblue;
padding: 12px;
}
gap), and distribution (justify-content).| Property (on the parent) | Does |
|---|---|
display: flex | Turns on flex; children become a row |
gap | Even space between children |
justify-content | Spread along the row: center, space-betweenโฆ |
align-items | Line up on the cross axis: center is the workhorse |
float (made for wrapping text around
images), inline-block with margin hacks, or even <table> tags for
layout. All fragile. Flexbox was the first tool built for arranging boxes โ centering and
even spacing became one line each. (Its 2D sibling, CSS Grid, comes later.)
a { }), delete it and refresh. If
nothing changes, it was dead weight. Messy CSS is where bugs hide.