<style>
#maindiv{
border: 1px solid black;
width: 800px;
height: 800px;
position: relative;
}
#test{
width: 200px;
font-size: 40px;
padding: 25px;
background-color: crimson;
color: white;
position: absolute;
top:50%;
left:50%;
transform: translate(-50%, -50%);
}
</style>
<div id="maindiv">
<div id="test">
가운데
</div>
</div>
<style>
div{
width: 200px;
font-size: 40px;
background-color: red;
color: white;
position: absolute;
top :50%;
left: 50%;
transform: translate(-50%, -50%);
margin: 10px auto;
}
#maindiv{
border: 1px solid black;
width: 800px;
height: 800px;
position: relative;
}
#test{
width: 200px;
font-size: 40px;
padding: 25px;
background-color: crimson;
color: white;
position: absolute;
top:50%;
left:50%;
transform: translate(-50%, -50%);
}
</style>
<div id="maindiv">
<div id="test">
가운데
</div>
</div>
화면의 크기 단위
px : 화면을 구성하는 단위
--> 필겟ㄹ은 디바이스 해상도에 따라 상대적인 크기를 갖는다.
--> 장치별로 픽셀의 크기는 제각각이기 때문에 픽셀의 단위는 명확하지 않다.
--> 대부분의 브라우저는 1px 96분의 1인치의 절대단위로 인식한다.
% : 백분률 단위의 상대 단위 요소에 지정된 사이즈에 상대적인 사이즈를 설정
viewport : 웹 페이지의 가시 영역 (눈에 보이는 영역)
--> viewport의 넓이가 1000px 높이가 600px 가정 후
viewport의 단위
1. vw : viewport 너비의 1/100
ex) 1vw : 10px
2. vh : viewport 높이의 1/100
ex) 1vh : 6px
3. vmin : viewport 넓이 또는 높이 중 작은 쪽의 1/100
ex) 넓이가 1000이고 높이가 600이니 적용 시 6px 적용
4. vmax : viewport 넓이 또는 높이 중 큰 쪽의 1/100
ex) 넓이가 1000이고 높이가 600이니 적용 시 10px 적용