Skip to content

Instantly share code, notes, and snippets.

@tinshade
Created April 2, 2021 05:46
Show Gist options
  • Save tinshade/5c1d7fcc602391839295c252d604c7d0 to your computer and use it in GitHub Desktop.
Save tinshade/5c1d7fcc602391839295c252d604c7d0 to your computer and use it in GitHub Desktop.
Quick and easy way to center elements; Vertically and Horizontally!
<!DOCTYPE html>
<html>
<head>
<title>Center anything with Grid</title>
<style>
*{
margin:0;
padding: 0;
}
#parent{
display: grid;
place-items: center;
background-color: lightblue;
min-height: 100vh;
}
#child{
min-height: 10vh;
min-width: 10vw;
padding: 2em;
background-color: #4563d1;
border-radius: 35px;
color: white;
font-family: monospace;
/*FOR SOME ANIMATIONS*/
animation-name: stretch;
animation-duration: 1.5s;
animation-timing-function: ease-out;
animation-delay: 0;
animation-direction: alternate;
animation-iteration-count: infinite;
animation-fill-mode: none;
animation-play-state: running;
/*FOR THE CHILD ELEMENTS IN THE CHILD ELEMENT*/
display: grid;
place-items: center;
}
a{
color: white;
text-decoration: none;
}
@keyframes stretch {
0% {
transform: scale(.9);
background-color: #4563d1;
border-radius: 40%;
}
50% {
background-color: #6f45d1;
}
100% {
transform: scale(1.5);
background-color: #a045d1;
}
}
</style>
</head>
<body>
<div id='parent'>
<div id='child'>
<h1><a href="https://github.com/tinshade" title="Follow me on GitHub!">@tinshade</a></h1>
</div>
</div>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment