CSS - Center both vertically and horizontally
Drozerah
Posted on July 24, 2019
Say you have a HTML <body></body>
tag and you want its child <div></div>
to be centered both vertically and horizontally with modern CSS : how to achieve that ?
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="/css/style.css">
</head>
<body>
<div>
<h1 class="title">Hello DEV!</h1>
</div>
</body>
</html>
Voilà!
See you next time!
Drozerah
💖 💪 🙅 🚩
Drozerah
Posted on July 24, 2019
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.