1. html 코드
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Button Design</title>
<link href="./style.css" rel="stylesheet">
</head>
<body>
<button class="btn btn-swap">
Buy <span>Sold Out</span>
</button>
</body>
</html>
2. css 코드
*{
margin:0;
padding:0;
box-sizing: border-box;
}
body{
background-color: #204063;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.btn{
background: none;
border: 2px solid white;
font-size: 35px;
color: white;
padding: 20px 40px;
width: 250px;
cursor: pointer;
position: relative;
}
.btn-swap span{
position: absolute;
top: 0;
left: 0;
padding: 20px 40px;
width: 100%;
opacity: 0;
transition: opacity 0.5s;
}
.btn-swap:hover span{
opacity: 1;
}
.btn-swap::before{
content:'';
width: 0%;
height: 100%;
position: absolute;
left: 0;
top: 0;
background-color: #ed4848;
transition: width 0.5s;
}
.btn-swap:hover::before{
width: 100%;
}
3. 결과
![](https://velog.velcdn.com/images/uniti0903/post/507422f6-0ac4-4b00-be56-4bb1e8ac8c71/image.png)