Web/CSS
[CSS-Visual Studio Code] Alignment 정렬
삐옥
2021. 12. 16. 13:33
Alignment 정렬
정렬, Alignment
- 인라인 태그와 블럭 태그의 수평 정렬
1. 인라인 태그
- 내용물 정렬 불가능 왜? 여백이 없다.
2. 블럭 태그
- 내용물 정렬 가능 왜? 여백이 있다.
태그 자체 정렬
1. 인라인 태그 자체를 정렬하려면
- 블럭 태그인 부모를 가져야 한다. > 즉, 부모에게 text-align을 사용한다.
2. 블럭 태그
- 불가능 > 좌우 공간이 없다. > 너비 100%
- 가능하게 하려면 좌우 margin이용
일반적인 정렬
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
|
<!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">
<title>Document</title>
<style>
#s1 {
background-color: yellow;
text-align: right;
}
#d1 {
background-color: yellow;
text-align: center;
}
</style>
</head>
<body>
<h1>인라인 태그</h1>
<span id="s1">인라인 태그</span>
<h1>블럭 태그</h1>
<div id="d1">블럭 태그</div>
</body>
</html>
|
cs |
태그자체 정렬
- HTML
1
2
3
4
5
|
#d2 {
background-color: palevioletred;
padding: 5px;
text-align: center;
}
|
cs |