Skip to content

Instantly share code, notes, and snippets.

@callezenwaka
Last active July 12, 2021 20:51
Show Gist options
  • Save callezenwaka/f64c19669b6e1b73ae2c4bf12905b952 to your computer and use it in GitHub Desktop.
Save callezenwaka/f64c19669b6e1b73ae2c4bf12905b952 to your computer and use it in GitHub Desktop.
How to center div with position absolute
<!DOCTYPE html>
<html>
<head>
<style>
.loader {
background-color: #000;
position: absolute;
height: 4rem;
width: 4rem;
left: 50%;
margin-left: -50px;
top: 50%;
margin-top: -50px;
z-index: 10000;
}
</style>
</head>
<body>
<div class="loader">
<div class="loader--wrapper">
<span>😎</span>
</div>
</div>
<div>Source: <a href="https://thoughtbot.com/blog/positioning>thoughtbot</a></div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment