CSS Cheat Sheet
Selectors
// element, class, id, descendant, child
p {} .card {} #main {} nav a {} ul > li {}
a:hover {} input:focus-visible {} li:nth-child(2n) {} .btn::after {}
[type="email"] {} .card:has(img) {} :is(h1, h2) {}
Box model and spacing
* { box-sizing: border-box; }
margin: 0 auto; padding: 1rem 2rem; border: 1px solid #ddd; border-radius: 12px;
width: 100%; max-width: 1200px; min-height: 100vh;
Flexbox
display: flex; flex-direction: row | column; flex-wrap: wrap; gap: 1rem;
justify-content: center | space-between; align-items: center | stretch;
flex: 1; flex: 0 0 200px; align-self: flex-end; order: 2;
Grid
display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem;
grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
grid-column: span 2; grid-area: main; place-items: center;
Text and colour
font: 600 1rem/1.6 system-ui, sans-serif; color: #333; text-align: center;
text-transform: uppercase; letter-spacing: 0.05em; text-decoration: none;
background: linear-gradient(135deg, #7c5cff, #22d3ee); opacity: 0.8;
box-shadow: 0 4px 12px rgb(0 0 0 / 0.1);
Positioning and responsive
position: relative | absolute | fixed | sticky; top: 0; z-index: 10;
@media (min-width: 768px) { .grid { grid-template-columns: 1fr 1fr; } }
img { max-width: 100%; height: auto; }
font-size: clamp(1rem, 2.5vw, 2rem);
Transitions and animations
transition: transform 0.2s ease, opacity 0.2s;
transform: translateY(-4px) scale(1.05) rotate(5deg);
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
animation: fade 0.4s ease-out both;
Full CSS documentation