button hover

In this example below you will see how to do a button hover with some HTML / CSS and Javascript

Thumbnail
This awesome code was written by jeanweb, you can see more from this user in the personal repository.
You can find the original code on Codepen.io
Copyright jeanweb ©
  • HTML
  • CSS
<!DOCTYPE html>
<html lang="en" >

<head>
  <meta charset="UTF-8">
  <title>button hover</title>
  
  
  
      <link rel="stylesheet" href="css/style.css">

  
</head>

<body>

  
<section>
  <div class="btn btn-1a"><a href="#">1a</a></div>
  <div class="btn btn-1b"><a href="#">1b</a></div>
  <div class="btn btn-1c"><a href="#">1c</a></div>
  <div class="btn btn-1d"><a href="#">1d</a></div>
</section>
<section>
  <div class="btn btn-2a"><a href="#">2a</a></div>
  <div class="btn btn-2b"><a href="#">2b</a></div>
  <div class="btn btn-2c"><a href="#">2c</a></div>
  <div class="btn btn-2d"><a href="#">2d</a></div>
</section>
<section>
  <div class="btn btn-3a"><a href="#">3a</a></div>
  <div class="btn btn-3b"><a href="#">3b</a></div>
  <div class="btn btn-3c"><a href="#">3c</a></div>
</section>
<section>
  <div class="btn btn-4a"><a href="#">4a</a></div>
  <div class="btn btn-4b"><a href="#">4b</a></div>
  <div class="btn btn-4c"><a href="#">4c</a></div>
  <div class="btn btn-4d"><a href="#">4d</a></div>
</section>
<section>
  <div class="btn btn-5a"><a href="#">5a</a></div>
  <div class="btn btn-5b"><a href="#">5b</a></div>
</section>
<section>
  <div class="link link-a"><a href="#">link-a</a></div>
  <div class="link link-b"><a href="#">link-b</a></div>
  <div class="link link-c"><a href="#">link-c</a></div>
  <div class="link link-d"><a href="#"><span data-hover="link-d">link-d</span></a></div>
  <div class="link link-e"><a href="#">link-e</a></div>
  <div class="link link-f"><a href="#">link-f</a></div>
  <div class="link link-g"><a href="#">link-g</a></div>
  <div class="link link-h"><a href="#">link-h</a></div>
  <div class="link link-i"><a href="#">link-i</a></div>
  <div class="link link-j"><a href="#">link-j</a></div>
</section>
<section>
  <div class="btn btn-6a"><a href="#">6a::before</a></div>
</section>
  
  

</body>

</html>

/*Downloaded from https://www.codeseek.co/jeanweb/button-hover-QvrOYx */
@charset "UTF-8";
* {
  box-size: border-box;
  color: #666;
  font-size: 12px;
  transition-duration: 0.5s;
}

body {
  background: #ccc;
  margin: 0;
  padding: 0;
}

a {
  text-decoration: none;
  display: block;
}

section {
  padding: 30px;
  border-bottom: 1px dashed #999;
}

.box {
  min-width: 200px;
  padding: 10px 20px;
  display: inline-block;
  vertical-align: top;
  border: 1px solid #c1c1c1;
}

.btn {
  width: 150px;
  padding: 10px;
  text-align: center;
  cursor: pointer;
  border: 2px solid #333;
  vertical-align: top;
  position: relative;
  margin: 10px 20px;
  display: inline-block;
}

.btn a {
  color: #333;
}

.link {
  min-width: 50px;
  text-align: center;
  cursor: pointer;
  vertical-align: top;
  position: relative;
  margin: 20px 30px;
  display: inline-block;
}

.link a {
  color: #333;
}

/*-----------btn-1a-------------- */
.btn-1a::after {
  content: "";
  background: #fcd04b;
  width: 100%;
  height: 0;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  transition-duration: 0.5s;
}

.btn-1a:hover::after,
.btn-1a:active::after {
  height: 100%;
}

/*-----------btn-1b-------------- */
.btn-1b::after {
  content: "";
  background: #fcd04b;
  width: 0;
  height: 100%;
  position: absolute;
  top: 0;
  left: 0;
  z-index: -1;
  transition-duration: 0.5s;
}

.btn-1b:hover::after,
.btn-1b:active::after {
  width: 100%;
}

/*-----------btn-1c-------------- */
.btn-1c::after {
  content: "";
  background: #fcd04b;
  width: 0;
  height: 100%;
  position: absolute;
  top: 0;
  right: 0;
  z-index: -1;
  transition-duration: 0.5s;
}

.btn-1c:hover::after,
.btn-1c:active::after {
  width: 100%;
}

/*-----------btn-1d-------------- */
.btn-1d::after {
  content: "";
  background: #fcd04b;
  width: 100%;
  height: 0;
  position: absolute;
  bottom: 0;
  left: 0;
  z-index: -1;
  transition-duration: 0.5s;
}

.btn-1d:hover::after,
.btn-1d:active::after {
  height: 100%;
}

/*------------------------------- */
/*-----------btn-2a-------------- */
.btn-2a {
  overflow: hidden;
}

.btn-2a::after {
  content: "";
  background: #fcd04b;
  width: 0;
  height: 103%;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -ms-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
  z-index: -1;
  opacity: 0;
  transition-duration: 0.5s;
}

.btn-2a:hover::after,
.btn-2a:active::after {
  width: 100%;
  opacity: 1;
}

/*-----------btn-2b-------------- */
.btn-2b {
  overflow: hidden;
}

.btn-2b::after {
  content: "";
  background: #fcd04b;
  width: 100%;
  height: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translateX(-50%) translateY(-50%);
  -moz-transform: translateX(-50%) translateY(-50%);
  -ms-transform: translateX(-50%) translateY(-50%);
  transform: translateX(-50%) translateY(-50%);
  z-index: -1;
  opacity: 0;
  transition-duration: 0.5s;
}

.btn-2b:hover::after,
.btn-2b:active::after {
  height: 101%;
  opacity: 1;
}

/*-----------btn-2c-------------- */
.btn-2c {
  overflow: hidden;
}

.btn-2c::after {
  content: "";
  background: #fcd04b;
  width: 100%;
  height: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translateX(-50%) translateY(-50%) rotate(45deg);
  -moz-transform: translateX(-50%) translateY(-50%) rotate(45deg);
  -ms-transform: translateX(-50%) translateY(-50%) rotate(45deg);
  transform: translateX(-50%) translateY(-50%) rotate(45deg);
  z-index: -1;
  opacity: 0;
  transition-duration: 0.5s;
}

.btn-2c:hover::after,
.btn-2c:active::after {
  height: 500%;
  opacity: 1;
}

/*-----------btn-2d-------------- */
.btn-2d {
  overflow: hidden;
}

.btn-2d::after {
  content: "";
  background: #fcd04b;
  width: 100%;
  height: 0;
  position: absolute;
  top: 50%;
  left: 50%;
  -webkit-transform: translateX(-50%) translateY(-50%) rotate(-45deg);
  -moz-transform: translateX(-50%) translateY(-50%) rotate(-45deg);
  -ms-transform: translateX(-50%) translateY(-50%) rotate(-45deg);
  transform: translateX(-50%) translateY(-50%) rotate(-45deg);
  z-index: -1;
  opacity: 0;
  transition-duration: 0.5s;
}

.btn-2d:hover::after,
.btn-2d:active::after {
  height: 500%;
  opacity: 1;
}

/*------------------------------- */
/*-----------btn-3a-------------- */
.btn-3a {
  border-radius: 5px;
  box-shadow: 0 6px #555;
  transition-duration: 0.5s;
  -webkit-transition: none;
  -moz-transition: none;
  transition: none;
}

.btn-3a:hover {
  box-shadow: 0 4px #555;
  top: 2px;
}

.btn-3a:active {
  box-shadow: 0 0 #555;
  top: 6px;
}

/*-----------btn-3b-------------- */
.btn-3b {
  border-radius: 40px;
  box-shadow: 0 6px #555;
  transition-duration: 0.5s;
  -webkit-transition: none;
  -moz-transition: none;
  transition: none;
}

.btn-3b:hover {
  box-shadow: 0 4px #555;
  top: 2px;
}

.btn-3b:active {
  box-shadow: 0 0 #555;
  top: 6px;
}

/*-----------btn-3c-------------- */
.btn-3c {
  border: 0px;
  background: #999;
  outline: 1px solid transparent;
  -webkit-transform-style: preserve-3d;
  -moz-transform-style: preserve-3d;
  transform-style: preserve-3d;
}

.btn-3c::after {
  content: "";
  background: #fcd04b;
  width: 100%;
  height: 40%;
  position: absolute;
  left: 0;
  top: 100%;
  z-index: -1;
  -webkit-transform-origin: 0% 0%;
  -webkit-transform: rotateX(-90deg);
  -moz-transform-origin: 0% 0%;
  -moz-transform: rotateX(-90deg);
  -ms-transform-origin: 0% 0%;
  -ms-transform: rotateX(-90deg);
  transform-origin: 0% 0%;
  transform: rotateX(-90deg);
}

.btn-3c:hover {
  -webkit-transform: rotateX(15deg);
  -moz-transform: rotateX(15deg);
  -ms-transform: rotateX(15deg);
  transform: rotateX(15deg);
}

/*------------------------------- */
/*-----------btn-4a-------------- */
.btn-4a {
  overflow: hidden;
}

.btn-4a::before {
  content: "→";
  font-size: 12px;
  padding: 10px 0;
  height: 100%;
  position: absolute;
  left: 130%;
  top: 0;
  transition-duration: 0.5s;
}

.btn-4a:hover::before {
  left: 80%;
}

/*-----------btn-4b-------------- */
.btn-4b {
  overflow: hidden;
}

.btn-4b::before {
  content: "→";
  font-size: 12px;
  padding: 10px 0;
  height: 100%;
  position: absolute;
  left: -50%;
  top: 0;
  transition-duration: 0.5s;
}

.btn-4b:hover::before {
  left: 10%;
}

/*-----------btn-4c-------------- */
.btn-4c {
  overflow: hidden;
}

.btn-4c::before {
  content: "→";
  font-size: 12px;
  padding: 10px 0;
  height: 100%;
  position: absolute;
  left: 70%;
  top: 0;
  opacity: 0;
  transition-duration: 0.5s;
}

.btn-4c:hover::before {
  left: 80%;
  opacity: 1;
}

/*-----------btn-4d-------------- */
.btn-4d {
  overflow: hidden;
}

.btn-4d::before {
  content: "→";
  font-size: 12px;
  padding: 10px 0;
  height: 100%;
  position: absolute;
  left: 30%;
  top: 0;
  opacity: 0;
  transition-duration: 0.5s;
}

.btn-4d:hover::before {
  left: 10%;
  opacity: 1;
}

/*------------------------------- */
/*-----------btn-5a-------------- */
.btn-5a {
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  backface-visibility: hidden;
}

.btn-5a a {
  display: inline-block;
}

.btn-5a:before {
  content: "→";
  font-size: 12px;
  padding: 10px 0;
  position: absolute;
  height: 100%;
  width: 100%;
  left: 0;
  top: -100%;
  transition-duration: 0.5s;
}

.btn-5a:hover a {
  -webkit-transform: translateY(300%);
  -moz-transform: translateY(300%);
  -ms-transform: translateY(300%);
  transform: translateY(300%);
}

.btn-5a:hover:before {
  top: 0;
}

/*-----------btn-5b-------------- */
.btn-5b {
  overflow: hidden;
  -webkit-backface-visibility: hidden;
  -moz-backface-visibility: hidden;
  backface-visibility: hidden;
}

.btn-5b a {
  display: inline-block;
}

.btn-5b:before {
  content: "→";
  font-size: 12px;
  padding: 10px 0;
  position: absolute;
  height: 100%;
  width: 100%;
  left: -100%;
  top: 0;
  transition-duration: 0.5s;
}

.btn-5b:hover a {
  -webkit-transform: translateX(800%);
  -moz-transform: translateX(800%);
  -ms-transform: translateX(800%);
  transform: translateX(800%);
}

.btn-5b:hover:before {
  left: 0;
}

/*------------------------------- */
/*-----------link-a-------------- */
.link-a a::before,
.link-a a::after {
  display: inline-block;
  opacity: 0;
  transition-duration: 0.5s;
}

.link-a a::before {
  margin-right: 10px;
  content: "[";
  -webkit-transform: translateX(20px);
  -moz-transform: translateX(20px);
  transform: translateX(20px);
}

.link-a a::after {
  margin-left: 10px;
  content: "]";
  -webkit-transform: translateX(-20px);
  -moz-transform: translateX(-20px);
  transform: translateX(-20px);
}

.link-a a:hover::before,
.link-a a:hover::after,
.link-a a:focus::before,
.link-a a:focus::after {
  opacity: 1;
  -webkit-transform: translateX(0px);
  -moz-transform: translateX(0px);
  transform: translateX(0px);
}

/*-----------link-b-------------- */
.link-b a::after {
  content: "";
  background: rgba(0, 0, 0, 0.1);
  width: 100%;
  height: 4px;
  position: absolute;
  top: 100%;
  left: 0;
  -webkit-transform: translateY(10px);
  -moz-transform: translateY(10px);
  transform: translateY(10px);
  opacity: 0;
  transition-duration: 0.5s;
}

.link-b a:hover::after,
.link-b a:focus::after {
  -webkit-transform: translateY(0px);
  -moz-transform: translateY(0px);
  transform: translateY(0px);
  opacity: 1;
}

/*-----------link-c-------------- */
.link-c a::after {
  content: "";
  background: #fff;
  width: 100%;
  height: 1px;
  position: absolute;
  top: 100%;
  left: 0;
  -webkit-transform: translateY(-10px);
  -moz-transform: translateY(-10px);
  transform: translateY(-10px);
  opacity: 0;
  transition-duration: 0.5s;
}

.link-c a:hover::after,
.link-c a:focus::after {
  height: 5px;
  opacity: 1;
  -webkit-transform: translateY(0px);
  -moz-transform: translateY(0px);
  transform: translateY(0px);
}

/*-----------link-d-------------- */
.link-d {
  overflow: hidden;
}

.link-d a span {
  position: relative;
  display: inline-block;
  transition-duration: 0.5s;
}

.link-d a span::before {
  position: absolute;
  top: 100%;
  content: attr(data-hover);
  font-weight: 700;
  -webkit-transform: translate3d(0, 0, 0);
  -moz-transform: translate3d(0, 0, 0);
  transform: translate3d(0, 0, 0);
}

.link-d a:hover span,
.link-d a:focus span {
  -webkit-transform: translateY(-100%);
  -moz-transform: translateY(-100%);
  transform: translateY(-100%);
}

/*-----------link-e-------------- */
.link-e a {
  margin: 0 10px;
  padding: 10px 20px;
}

.link-e a::before {
  content: "";
  background: #333;
  width: 100%;
  height: 2px;
  position: absolute;
  top: 0;
  left: 0;
  transition-duration: 0.5s;
}

.link-e a::after {
  content: "";
  background: #333;
  width: 2px;
  height: 2px;
  position: absolute;
  top: 0;
  left: 0;
  transition-duration: 0.5s;
}

.link-e a:hover::before {
  top: 100%;
  opacity: 1;
}

.link-e a:hover::after {
  height: 100%;
}

/*-----------link-f-------------- */
.link-f a {
  margin: 5px;
}

.link-f a::before,
.link-f a::after {
  content: "";
  background: #566473;
  width: 100%;
  height: 2px;
  position: absolute;
  top: 100%;
  left: 0;
  -webkit-transform: scale(0.85);
  -moz-transform: scale(0.85);
  transform: scale(0.85);
  transition-duration: 0.5s;
}

.link-f a::after {
  opacity: 0;
  -webkit-transition: top 0.3s, opacity 0.3s, -webkit-transform 0.3s;
  -moz-transition: top 0.3s, opacity 0.3s, -moz-transform 0.3s;
  transition: top 0.3s, opacity 0.3s, transform 0.3s;
}

.link-f a:hover::before,
.link-f a:hover::after,
.link-f a:focus::before,
.link-f a:focus::after {
  -webkit-transform: scale(1);
  -moz-transform: scale(1);
  transform: scale(1);
}

.link-f a:hover::after,
.link-f a:focus::after {
  top: 0%;
  opacity: 1;
}

/*-----------btn-6a-------------- */
.btn-6a {
  overflow: hidden;
  padding: 30px 10px;
}

.btn-6a::before {
  content: "";
  width: 350px;
  height: 350px;
  border-radius: 150px;
  background: #fff;
  position: absolute;
  top: 70%;
  left: 50%;
  transform: translateX(-50%);
  z-index: -1;
  transition-duration: 0.5s;
  animation: wave 4s infinite linear;
}
@keyframes wave {
  0% {
    transform: translateX(-50%) rotate(0deg);
  }
  100% {
    transform: translateX(-50%) rotate(360deg);
  }
}
.btn-6a:hover::before {
  top: 20%;
}

Comments