3D 변환함수를 이용하여 flip 제작하기
rotateY + perspective + backface-visibility + z-index !!!
고려해야할 점
- 앞면과 뒷면을 어떻게 겹칠 것인가? : position absolute와 relative 이용하기.
- 앞면과 뒷면 회전은 어떻게 할 것인가? : rotateY 이용하기.
- 회전 시 3D 표현은 어떻게 할 것인가? : perspective 이용하기.
- 회전 시에 보이는 면은 어떻게 할 것인가? : z-index, backface-visibility 이용하기.
<!DOCTYPE html>
<html lang="ko">
<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>Flip</title>
<link rel="stylesheet" href="./01flip.css" />
</head>
<body>
<div class="flip">
<div class="flip__container">
<div class="front">
<h1>앞면</h1>
</div>
<div class="back">
<h1>뒷면</h1>
</div>
</div>
</div>
</body>
</html>
일단 flip을 적용할 부모 태그를 만들고, flip를 적용할 태그를 만들어서 앞면과 뒷면을 넣어준다.
- flip 부모 태그에 적용할 것
- flip 자체를 적용할 것
이렇게 2가지로 나누어서 생각해봐야 한다.
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
/* 1. flip 부모에 적용할 것 */
.flip {
width: 300px;
height: 300px;
position: relative;
perspective: 1100px;
margin: 100px;
}
/* 2. flip 그 자체에 적용할 것 */
.flip__container {
width: 100%;
height: 100%;
position: relative;
color: white;
font-size: 30px;
text-align: center;
line-height: 300px;
transition: 0.4s;
}
.front,
.back {
width: 100%;
height: 100%;
border-radius: 50%;
position: absolute;
}
.front {
background-color: tomato;
/* front에 hidden 설정하여 뒤집으면 back 보이게 만듦 */
backface-visibility: hidden;
}
.back {
background-color: royalblue;
z-index: -1;
/* 뒷면 글자를 제대로 보여주기 위하여 */
transform: rotateY(180deg);
}
.flip:hover .flip__container {
transform: rotateY(180deg);
transition: 0.4s;
.front {
z-index: -1;
}
}
hover 시에 z-index 변경시켜서 뒤로 보내버리고, 전환과 변환을 동시에 적용하면 자연스럽게 원하는 모양으로 제작 가능하다.
'web > html css' 카테고리의 다른 글
[패스트캠퍼스] 국비지원 14일차 오버워치 캐릭터 선정 페이지 (0) | 2023.05.19 |
---|---|
[패스트캠퍼스] 국비지원 13일차 학습일지 (0) | 2023.05.17 |
[패스트캠퍼스] 국비지원 6일차 학습일지 (0) | 2023.05.10 |
[패스트캠퍼스] 국비지원 5일차 학습일지 (0) | 2023.05.09 |
[패스트캠퍼스] 국비지원 3일차 학습일지 (0) | 2023.05.07 |