이렇게 중앙배치를 하고 싶을 때 방법이 여러가지가 있다.
1. position, margin 을 이용하는 방법
2. flex 를 이용하는 방법
3. position, transform-translate 이용
1) 부모요소 너비의 50% 되는 위치로 이동
2) 자식 요소 너비의 50% 만큼 왼쪽, 위쪽으로 이동
<!DOCTYPE html>
<html lang="ko">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
.container {
background-color: black;
width: 500px;
height: 300px;
margin: auto;
.item {
text-align: center;
.item1,.item2 {
background-color: green;
border: 2px dotted white;
width: 200px;
height: 50px;
display: inline-block;
margin: 10px;
}
}
}
</style>
</head>
<body>
<div class="container">
<div class="item">
<div class="item1"></div>
<div class="item2"></div>
</div>
</div>
</body>
</html>
'IT > HTML, CSS' 카테고리의 다른 글
가상요소 (0) | 2024.09.08 |
---|---|
HTML 특수문자 코드 (1) | 2024.09.07 |
input 태그 속성 (0) | 2024.08.19 |
같은 비율로 정렬 flex 이용 (0) | 2024.08.16 |
화면 가득 채우는 박스 만들기 (0) | 2024.08.06 |