DEV Community

Cover image for How to create Advanced Button hover effect in HTML and CSS
Manoj Rathod
Manoj Rathod

Posted on

How to create Advanced Button hover effect in HTML and CSS

Here is code for creating advanced button hover effect

See demo:- (https://codepen.io/iammanojrathod/pen/vYevVap)

HTML code:-

<header>
 <button class="btn1">Button1</button>
  <button class="btn2">Button2</button>
</header>
Enter fullscreen mode Exit fullscreen mode

CSS code:-

*{
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}
header{
  position: relative;
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: black;
}
button{
  margin-right: 20px;
}
.btn1{
  color: #fff;
}
.btn2{
  color: #000;
}
.btn1, .btn2{
  position: relative;
  background: transparent;
  padding: 20px 30px;
  font-size: 30px;
  border: 2px solid #fff;
  cursor: pointer;
  z-index: 10;
  trasition: all 0.5s ease;
}
.btn1:before,
.btn1:after,
.btn2:before,
.btn2:after{
  content: '';
  position: absolute;
  top: 0;
  width: 50%;
  height: 100%;
  background: #fff;
  z-index: -1;
} 
.btn1:before {
  left: 0;
  transform: scaleX(0);
  transition: transform 0.5s;
  transform-origin: left;
}
.btn1:hover:before{
  transform: scaleX(1);
  transition: transform 0.5s;
  transform-origin: right;
}
.btn1:after {
  right: 0;
  transform: scaleX(0);
  transition: transform 0.5s;
  transform-origin: right;
}
.btn1:hover::after{
 transform: scaleX(1);
  transition: transform 0.5s;
  transform-origin: left;
}
.btn2:before {
  left: 0;
  transform: scaleX(1);
  transition: transform 0.5s;
  transform-origin: left;
}
.btn2:hover:before{
  transform: scaleX(0);
  transition: transform 0.5s;
  transform-origin: right;
}
.btn2:after {
  right: 0;
  transform: scaleX(1);
  transition: transform 0.5s;
  transform-origin: right;
}
.btn2:hover::after{
 transform: scaleX(0);
  transition: transform 0.5s;
  transform-origin: left;
}
.btn1:hover{
  color: #000;
}
.btn2:hover{
  color: #fff;
}
Enter fullscreen mode Exit fullscreen mode

Thanks You ❤

Top comments (0)