Skip to content

Instantly share code, notes, and snippets.

@awareness481
Last active February 14, 2020 04:27
Show Gist options
  • Save awareness481/210936caa7e2e34af00adec8f1ac4ccd to your computer and use it in GitHub Desktop.
Save awareness481/210936caa7e2e34af00adec8f1ac4ccd to your computer and use it in GitHub Desktop.
Slide in background CSS animation on hover
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width">
<title>repl.it</title>
<link href="style.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class='container'>
<div class='effect'>
</div>
</div>
<script src="script.js">
</script>
</body>
</html>
.container {
width: 200px;
height: 200px;
position: relative;
border: 1px solid black;
}
.effect {
background-color: blue;
width: 100%;
height: 100%;
position: absolute;
bottom: -100%;
}
.container:hover .effect {
animation-duration: 0.4s;
animation-name: slidein;
animation-fill-mode: forwards;
}
@keyframes slidein {
to {
bottom: 0;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment