[구성효과]
1. text 색상이 #000 -> #fff로 바뀐다.
2. 마우스가 올라갈 시 버튼 배경의 painting 효과가 나타난다.
두개의 효과 다 transition 을 사용해 구현할수 있고, painting 효과는 넓이가 0%->100% 로 변환 하게 하면 된다.
painting 효과는 img 파일.
[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 : painting</title>
<link rel="stylesheet" href="./style.css" />
</head>
<body>
<div class="container">
<a href="#"><span>Read More</span></a>
<a href="#"><span>Read More</span></a>
</div>
</body>
</html>
[css]
@import url("https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700;800;900&display=swap");
* {
box-sizing: border-box;
margin: 0;
padding: 0;
font-family: "Poppins", sans-serif;
}
body {
background-color: #daffc2;
}
.container {
display: flex;
justify-content: center;
align-items: center;
min-height: 100vh;
}
.container a {
position: relative;
display: inline-flex;
justify-content: center;
align-items: center;
text-decoration: none;
margin: 10px 0;
width: 300px;
height: 75px;
font-size: 24px;
font-weight: 600;
color: #000;
transition: 0.5s;
}
.container a:hover {
color: #fff;
}
.container a::before {
content: "";
position: absolute;
top: 0;
left: 0;
width: 0;
height: 100%;
background: url(./btn-bg1.png);
/* cover -> 배경이미지가 요소보다 클때 맞추기 위해 이미지를 줄이는 방법 */
/* contain- > 배경이미지가 요소보다 작을때 맞추기 위해 이미지를 키우는 방법 */
background-size: cover;
/* transform-origin은 형태를 변경시키는 기준점을 지정한다. */
transform-origin: left;
transition: 0.5s;
}
.container a:hover::before {
width: 100%;
}
.container a:nth-child(2)::before {
background-image: url(./btn-bg2.png);
}
/* span 이 제일 상위에 위치하기 위함 */
.container a span {
position: relative;
z-index: 1;
}
'WEB animation & effect > button' 카테고리의 다른 글
반짝이는 버튼 effect (0) | 2021.10.04 |
---|---|
그라데이션 버튼 effect (0) | 2021.10.04 |
버튼 hover 효과 : square (0) | 2021.09.29 |
버튼 하단 슬라이더 (0) | 2021.09.06 |