HTML File: (index.html)
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Button Hover Effect</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<a href="#">Button</a>
</body>
</html>
CSS File: (style.css)
body
{
margin: 0;
padding: 0;
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
a
{
position: relative;
padding: 8px 30px;
color: #000;
text-transform: uppercase;
text-decoration: none;
font-size: 20px;
border: 2px solid #000;
transition: 0.5s;
}
a:hover
{
color: #fff;
}
a::before
{
content: '';
position: absolute;
top: 0;
left: 0;
width:50%;
height: 100%;
background: #000;
z-index: -1;
transform: scaleX(0);
transition: transform 0.5s;
transform-origin: left;
}
a:hover::before
{
transform: scaleX(1);
transition: transform 0.5s;
transform-origin: right;
}
a::after
{
content: '';
position: absolute;
top: 0;
right: 0;
width:50%;
height: 100%;
background: #000;
z-index: -1;
transform: scaleX(0);
transition: transform 0.5s;
transform-origin: right;
}
a:hover::after
{
transform: scaleX(1);
transition: transform 0.5s;
transform-origin: left;
}
Leave a Reply