CSS layout cheat sheet · Web Dev Topics · Learn the Web
CSS layout cheat sheet · Web Dev Topics · Learn the Web
Layout mechanics
Centering elements
<h1>Micropachycephalosaurus</h1> <h2>
<p>Longest dinosaur name <a
ever!</p> bones!
</div> </div
</div>
.card
.banner { display
position: relative; flex-dir
} column
justify-
.content { center
position: absolute; align-co
left: 50%; center
transform: translateX(-50%); align-it
} }
Or vertical centering too… This will be co
:
Or vertical centering too… This will be co
.content { within the box
position: absolute; See the flexb
left: 50%; more details
top: 50%;
transform: translate(-50%, cheat-sheet/
-50%);
}
Common code