css
div 영역 안에 div를 가로로 나열하여 배치하고 가운데 정렬하기
제뉴어리맨
2022. 6. 4. 12:53
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
#container {
background-color: gray;
width: 1000px;
height: 600px;
border: 2px solid blue;
margin: 0 auto; /* container 영역을 브라우저에서 가운데 정렬하기 위해 auto설정 */
text-align: center; /* inline-block화 된 div들을 텍스트 마냥 center로 정렬*/
}
#container div{
display: inline-block; /* 가로로 나열하기 위해 block레벨 요소를 inline-block레벨로 전환 */
width: 200px; /* 영역 크기 지정 안해주면 inline 레벨처럼 내용물 만큼만 차지하기 때문에 크기 지정 */
height: 200px; /* 영역 크기 지정 안해주면 inline 레벨처럼 내용물 만큼만 차지하기 때문에 크기 지정 */
border: 2px solid aqua;
background: orange;
}
</style>
<title>Document</title>
</head>
<body>
<div id="container">
<div>
첫번째
</div>
<div>
두번째
</div>
</div>
</body>
</html>
결과 화면