perspective
를 설정하면 3d 효과를 줄 수 있음<div class="world">
<div class="card">CARD</div>
<div class="card">CARD</div>
<div class="card">CARD</div>
</div>
.world{
display: flex;
align-items: center;
justify-content: center;
width:80vw;
height: 80vh;
background-color: yellow;
perspective : 500px
}
.card{
display: flex;
align-items: center;
justify-content: center;
margin:1em;
width:100px;
height: 150px;
background-color: red;
border-radius: 0.5em;
font-size:1.5rem;
transform: rotateY(45deg) ;
}
.world{
display: flex;
align-items: center;
justify-content: center;
width:80vw;
height: 80vh;
background-color: yellow;
}
.card{
display: flex;
align-items: center;
justify-content: center;
margin:1em;
width:100px;
height: 150px;
background-color: red;
border-radius: 0.5em;
font-size:1.5rem;
transform: rotateY(45deg) perspective(500px);
}
flat(default)
: 자식 요소는 2D의 2차원에서 부모 요소와 동일한 평면에 배치preserve-3d
: 3D 공간에 배치되도록 됩니다.<!--html-->
<div class="world">
<div class="card">
<div class="card-side card-side-front">F</div>
<div class="card-side card-side-back">B</div>
</div>
</div>
/*css*/
.world{
display: flex;
align-items: center;
justify-content: center;
width:80vw;
height: 80vh;
background-color: yellow;
perspective: 500px;
}
.card{
position:relative;
width:100px;
height: 150px;
transform: perspective(500px) rotateY(0deg) ;
transition: 1s;
transform-style:preserve-3d;
}
.card-side{
position: absolute;
left:0;
top:0;
width:100%;
height: 100%;
display: flex;
align-items: center;
justify-content: center;
border-radius: 0.5em;
font-size:1.5rem;
backface-visibility: hidden;
}
.card-side-front{
z-index: 1;
background-color: white;
}
.card-side-back{
background-color: red;
transform: rotateY(180deg);
}
.world:hover .card{
transform: rotateY(180deg);
}
📑 reference