<div id="wrap">
<div class="container type01">
<div class="centerBox">
<span>가운데 정렬</span>
</div>
</div>
<div class="container type02">
<div class="centerBox">
<span>가운데 정렬</span>
</div>
</div>
<div class="contBox">
<div class="container type03">
<div class="centerBox">
<span>가운데 정렬</span>
</div>
</div>
</div>
</div>
#wrap{height: 100%;
.container{
&.type01{height: 100%; display: flex; align-items: center; justify-content: center;}
&.type02{display: flex; align-items: center; justify-content: center; height: 100vh;}
&.type03{position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);}
}
}
.contBox{position: relative; height: 100%;}
.centerBox{padding: 50px; border: 2px solid #000; font-size: 22px; font-family: 'Noto Sans';}
#wrap{
height: 100%;
}
#wrap .container.type01 {
height: 100%;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
}
#wrap .container.type02 {
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
-webkit-box-pack: center;
-ms-flex-pack: center;
justify-content: center;
height: 100vh;
}
#wrap .container.type03 {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%,-50%);
}
.contBox{
position: relative;
height: 100%;
}
.centerBox {
padding: 50px;
border: 2px solid #000;
font-size: 22px;
font-family: 'Noto Sans';
}
아래 주소를 복사하여 다른 곳에 붙여넣으세요.
모바일 환경에서는 코드 결과가 gif로 표시됩니다.
그래도 결과를 볼까요?
(제대로 된 결과를 보려면 노트북 또는 데스크탑에서 실행해주세요.)