CSS ์ ๋๋ฉ์ด์ : ์นด๋ ๋ค์ง๊ธฐ ์ ๋๋ฉ์ด์
์ค๋์ ๋ง์ฐ์ค๋ฅผ ์ค๋ฒํ์ ๋ ์นด๋๊ฐ ๋ค์งํ๋ ๋ฏํ ์ ๋๋ฉ์ด์ ์ด ๋ํ๋๋๋ก ์์ ํด ๋ณด๊ฒ ์ต๋๋ค. ์์ ํด๋ณผ ์ ๋๋ฉ์ด์ ์ ๋ค์๊ณผ ๊ฐ์ต๋๋ค.
1. HTML ์์ค
<div class="hover__wrap">
<div class="hover__updown">
<figure class="front">
<img src="img01">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>๋ง์ฐ์ค๋ฅผ ์ฌ๋ฆฌ๋ฉด Up</p>
</figcaption>
</figure>
<figure class="back">
<img src="img02">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>๋ง์ฐ์ค๋ฅผ ๋ด๋ฆฌ๋ฉด Down</p>
</figcaption>
</figure>
</div>
<div class="hover__leftright">
<figure class="front">
<img src="img03">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>๋ง์ฐ์ค๋ฅผ ์ฌ๋ฆฌ๋ฉด to Right</p>
</figcaption>
</figure>
<figure class="back">
<img src="img04">
<figcaption>
<h3>Mouse Hover Effect</h3>
<p>๋ง์ฐ์ค๋ฅผ ๋ด๋ฆฌ๋ฉด to Left</p>
</figcaption>
</figure>
</div>
</div>
HTML ์์ค๋ ์ ์ฒด์ ํด๋นํ๋ hover__wrap ์์ hover__updown, hover__leftright ๋ ๊ฐ์ div ๋ฐ์ค๋ฅผ ๋ง๋ค์ด ์ค๋๋ค. ๊ทธ ์์๋ ๊ฐ๊ฐ ์, ๋ค์ ํด๋นํ๋ ์ด๋ฏธ์ง๋ฅผ ์ฝ์ ํ๊ณ , figcaption ํ๊ทธ ์์ ์ ๋ชฉ๊ณผ ์ค๋ช ์ ์์ฑํด ์ฃผ๋ฉด ๋ฉ๋๋ค.
2. CSS ์์ค
.hover__wrap {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
}
.hover__wrap > div {
max-width: 400px;
margin: 3%;
position: relative;
perspective: 1000px;
}
.hover__wrap > div img {
width: 100%;
border: 10px solid #F0F8FF;
box-shadow: 2px 2px 2px 2px rgba(0,0,0,0.2);
box-sizing: border-box;
vertical-align: top;
}
.hover__wrap > div .front {
transition: transform 1s;
backface-visibility: hidden;
transform-style: preserve-3d;
}
.hover__wrap > div .back {
position: absolute;
left: 0;
top: 0;
z-index: -1;
transition: transform 1s;
transform-style: preserve-3d;
}
.hover__wrap > div figcaption {
background: rgba(0, 0, 0, 0.4);
color: #F8F8FF;
padding: 10px;
text-align: center;
line-height: 1.5;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%) translateZ(100px);
width: 60%;
backface-visibility: hidden;
}
/* hover effect */
.hover__updown .front {
transform: rotateX(0deg);
}
.hover__updown:hover .front {
transform: rotateX(180deg);
}
.hover__updown .back {
transform: rotateX(-180deg);
}
.hover__updown:hover .back {
transform: rotateX(0deg);
}
.hover__leftright .front {
transform: rotateY(0deg);
}
.hover__leftright:hover .front {
transform: rotateY(180deg);
}
.hover__leftright .back {
transform: rotateY(-180deg);
}
.hover__leftright:hover .back {
transform: rotateY(0deg);
}
hover__wrap์๋ flex ์์ฑ์ ์ด์ฉํ์ฌ ์ด๋ฏธ์ง๋ค์ ๊ฐ์ด๋ฐ ์ ๋ ฌํด ์ค๋๋ค.
prespective ์์ฑ์ CSS๋ก 3D ํจ๊ณผ๋ฅผ ์ฃผ๊ธฐ ์ํด์ ๊ฐ์ฅ ์ค์ํ ๊ฒ์ผ๋ก, ์ด
์์ฑ์ ์ฌ์ฉํ๋ฉด ์๊ทผ๊ฐ์ ์ค ์ ์์ต๋๋ค. ๊ฐ์ด ์์์๋ก ๊ฐ๊น๊ฒ ๋ณด์ด๊ณ ,
ํด์๋ก ๋ฉ๊ฒ ๋ณด์
๋๋ค.
backface-visibility ์์ฑ์ ์์์ ๋ค์ชฝ์์ ์๋ฉด์ด ๋ณด์ด๊ฒ ํ ์ง ์ ํ๋
์์ฑ์
๋๋ค. ์ด ์์ฑ์ hidden ๊ฐ์ ๋ถ์ฌํจ์ผ๋ก์จ, ์์๊ฐ ๋ค์งํ์ ๋ ๋ณด์ด์ง ์๊ฒ
์จ๊ธฐ๊ณ , ๋ค์ ์๋ ์์์ธ back ์ด๋ฏธ์ง๊ฐ ๋ณด์ด๊ฒ ๋๋ ๊ฒ์
๋๋ค.
body์ ๊ทธ๋ผ๋ฐ์ด์
์์ค๋ ์๋ตํ์ต๋๋ค. ์์ธํ ์์ค๋ ์ฝ๋ํ์ ์ฐธ๊ณ ํด ์ฃผ์ธ์.
์์ HTML, CSS ์์ค๋ฅผ ํฉ์น๋ฉด ์ ๋๋ฉ์ด์ ์ด ์์ฑ๋ฉ๋๋ค. ์ด๋ฒ์๋ ๊ฐ๋จํ์ง ์์ต๋๋ค. ์์์ฃ ?
'CSS' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
CSS ์ ๋๋ฉ์ด์ ๋ง๋ค๊ธฐ : 3D ๋ฐ์ค ์ ๋๋ฉ์ด์ (9) | 2022.09.22 |
---|---|
CSS ์ ๋๋ฉ์ด์ ๋ง๋ค๊ธฐ : ํตํต ํ๋ ๊ธ์ (1) | 2022.09.22 |
CSS ์ ๋๋ฉ์ด์ ๋ง๋ค๊ธฐ : ์ผ๋ ์ด๋ ์ ๋๋ฉ์ด์ (8) | 2022.09.19 |
CSS ์ ๋๋ฉ์ด์ ๋ง๋ค๊ธฐ : GIF ์ด๋ฏธ์ง ์ ๋๋ฉ์ด์ ๊ตฌํํ๊ธฐ (9) | 2022.09.08 |
CSS ์ ๋๋ฉ์ด์ ๋ง๋ค๊ธฐ : ์ ๋๋ฉ์ด์ ๊ธฐ์ด (3) | 2022.09.08 |
๋๊ธ