요소의 위치 지정 기준
position 선언 후 top, bottom, right, left, z-index 값을 지정해 위치 지정한다.
어떤 요소가 사용자와 더 가깝게 있는지(위에 쌓이는지) 결정
.container {
width: 300px;
background-color: orange;
position: relative;
}
.container .box {
width: 100px;
height: 100px;
border: 4px dashed black;
background-color: green;
margin-bottom: 5px;
}
.container .box:nth-child(1) {
}
.container .box:nth-child(2) {
position: absolute;
top: 50px;
left: 80px;
}
.container .box:nth-child(3) {
}
2번 box가 1번 조건에 부합하기 때문에 가장 위쪽에 쌓여있다.
1번 box에 position 값이 들어가도 3번 조건에 의해 가장 위쪽에 쌓이게 된다.
3번 box에 position 값이 들어가면?
.container {
width: 300px;
background-color: orange;
position: relative;
}
.container .box {
width: 100px;
height: 100px;
border: 4px dashed black;
background-color: green;
margin-bottom: 5px;
}
.container .box:nth-child(1) {
position: relative;
}
.container .box:nth-child(2) {
position: absolute;
top: 50px;
left: 80px;
}
.container .box:nth-child(3) {
/* 이 부분 추가!*/
position: relative;
}
3번 box가 HTML 구조에서 가장 나중에 작성 되었기 때문에 가장 위쪽에 쌓인다.
2번 box에 z-index 값을 넣어주면?
.container {
width: 300px;
background-color: orange;
position: relative;
}
.container .box {
width: 100px;
height: 100px;
border: 4px dashed black;
background-color: green;
margin-bottom: 5px;
}
.container .box:nth-child(1) {
position: relative;
}
.container .box:nth-child(2) {
position: absolute;
top: 50px;
left: 80px;
/* 이 부분 추가! */
z-index: 1;
}
.container .box:nth-child(3) {
position: relative;
}
1번 조건은 모두 같고, 2번 조건에 의해 z-index 값을 가진 2번 box가 가장 위에 쌓여 첫번째 사진과 결과가 같다.
요소의 쌓임 정도를 지정 (두번째 조건)
숫자가 높을 수록 위에 쌓인다.
position 값으로 absolute, fixed가 지정된 요소는 display가 block으로 변경된다.
부모 요소에 diplay: flex;
를 추가하여 1차원의 레이아웃 배치가 가능하게 한다.
display: flex;
속성이 부여된 부모 요소
order
flex items의 순서
기본 값은 0, 숫자가 작을수록 먼저 정렬 (음수 가능)
flex-grow
flex items의 증가 너비 비율
기본 값은 0
flex-shrink
flex items의 감소 너비 비율
기본 값은 1. flex container의 너비가 작을 때 flex items들이 줄어드는 비율
flex-shrink의 값이 0이면 flex container의 너비가 작아도 자신들의 너비를 유지하며 존재한다.
flex-basis
flex items의 공간 배분 전 기본 너비
기본 값은 content의 너비(auto)
flex-basis의 값이 0이면 content의 너비는 무시하고 요소 박스의 너비 비율로 맞춰준다.