๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
CSS

[CSS] ์• ๋‹ˆ๋ฉ”์ด์…˜05 : ๊น์ฆค๋‚˜๋Š” ์ž…์ฒด ํšจ๊ณผ

by _ํ† ๋งคํ†  2022. 9. 21.
728x90

CSS : ์• ๋‹ˆ๋ฉ”๋‹ˆ์…˜ ๋งŒ๋“ค๊ธฐ : ๐Ÿ•ถ ์ž…์ฒด์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜ ์ž‘์—…~ ๐Ÿ˜Ž + ๋งˆ์šฐ์Šค ์˜ค๋ฒ„ ํšจ๊ณผ ๐Ÿ–ฑ

์ด๋ฒˆ ์‹œ๊ฐ„์—๋Š” CSS ์‹ค์Šต์œผ๋กœ ์ž…์ฒด์ ์ธ ์• ๋‹ˆ๋ฉ”์ด์…˜์„ ๋งŒ๋“ค์–ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค~~! ์˜ค๋Š˜์˜ ํฌ์ธํŠธ ์†์„ฑ์€ ๋ฐ”๋กœ~~ transform-style: preserve-3d;์ž…๋‹ˆ๋‹ค!


#1. HTML

๊ตฌ์กฐ๋ฅผ ์•ž๊ณผ ๋’ค๊ฐ€ ๋”ฐ๋กœ ์žˆ๋‹ค ์ƒ๊ฐํ•˜์—ฌ ๋งˆํฌ์—…์„ ํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

<div class="hover__wrap">
  <div class="hover__updown">
    <figure class="front">
      <img src="https://user-images.githubusercontent.com/106949433/191177895-3875da4c-06b6-42f8-83cb-b5a7fe7ac88a.jpg" alt="hoverUp ์ด๋ฏธ์ง€">
      <figcaption>
        <h3>Mouse Hover Effect</h3>
        <p>๋งˆ์šฐ์Šค ์˜ฌ๋ฆฌ๋ฉด Up</p>
      </figcaption>
    </figure>
    <figure class="back">
      <img src="https://user-images.githubusercontent.com/106949433/191177915-75551c83-9f83-49cc-a1fc-3eff65e014df.jpg" alt="hoverDown ์ด๋ฏธ์ง€">
      <figcaption>
        <h3>Mouse Hover Effect</h3>
        <p>๋งˆ์šฐ์Šค ๋‚ด๋ฆฌ๋ฉด Down</p>
      </figcaption>
    </figure>
  </div>
  
  <div class="hover__leftright">
    
    <figure class="front">
      <img src="https://user-images.githubusercontent.com/106949433/191177923-3b338ef2-50ae-48c3-83d1-827f29e39b99.jpg" alt="hoverLeft ์ด๋ฏธ์ง€">
      <figcaption>
        <h3>Mouse Hover Effect</h3>
        <p>๋งˆ์šฐ์Šค ์˜ฌ๋ฆฌ๋ฉด to Right</p>
      </figcaption>
    </figure>
    
    <figure class="back">
      <img src="https://user-images.githubusercontent.com/106949433/191177925-8578bc0b-b09d-4e7c-9b95-21f998b1ae84.jpg" alt="hoverRight ์ด๋ฏธ์ง€">
      <figcaption>
        <h3>Mouse Hover Effect</h3>
        <p>๋งˆ์šฐ์Šค ๋‚ด๋ฆฌ๋ฉด to Left</p>
      </figcaption>
    </figure>
  </div>
</div>

#2. CSS

๋‹ค์Œ์€ CSS ์ฝ”๋“œ ์ž…๋‹ˆ๋‹ค!
์˜ค๋Š˜์˜ ํฌ์ธํŠธ๋Š” transform-style: preserve-3d;์™€ perspective๋กœ ์ž…์ฒด์ ์ธ ํšจ๊ณผ๋ฅผ ์ฃผ๊ณ  ์‹ถ์„ ๋•Œ ์‚ฌ์šฉํ•˜๋Š” ์†์„ฑ์ž…๋‹ˆ๋‹ค.
perspective == ์›๊ทผ๊ฐ์„ ์ฃผ๋Š” ์†์„ฑ

@font-face {
  font-family: โ€˜LocusSangsangโ€™;
  font-weight: normal;
  font-style: normal;
  src: url(โ€˜https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.eotโ€™);
  src: url(โ€˜https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.eot?#iefixโ€™) format(โ€˜embedded-opentypeโ€™),
       url(โ€˜https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.woff2โ€™) format(โ€˜woff2โ€™),
       url(โ€˜https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.woffโ€™) format(โ€˜woffโ€™),
       url(โ€˜https://cdn.jsdelivr.net/gh/webfontworld/locus/LocusSangsang.ttfโ€™) format(โ€œtruetypeโ€);
  font-display: swap;
}
body {
font-family: โ€˜LocusSangsangโ€™;
background-image: linear-gradient(135deg, #191970 0%, #483088 40%, #0370DB 100%);
height: 100vh;
}
.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: 5px 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__updown {
}
.hover__leftright {
}
/* mouse 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);
}

#3. ๊ฒฐ๊ณผ๋ณด๊ธฐ

728x90

๋Œ“๊ธ€


Lucky Charms Rainbow
js
html
css