<div class="z-one"></div> <div class="z-two"></div>
.z-one { position: absolute; width: 200px; height: 400px; background-color: yellow;} .z-two { position: absolute; width: 200px; height: 300px; background-color: blue;}
이렇게 3차원 포지션값인 relative
,absolute
나 fixed
를 쓰면 겹침
간단하게 말해서 z-index
는 우선순위결정
아무값도 없으면 최초값은 0
더 높은숫자가 위로 올라옴
z-index: 20;
형제관계에선 순수 3차원(absolute
나 fixed
) 포지션을 줄때
첫번째한테 겹쳐짐
두번째 한테주면 안겹쳐짐,, 이라는데 2개이상의 경우엔 어케되는걸까
<header></header> <div class="left"></div> <div class="center"></div> <div class="right"></div> <footer></footer>
header{ width: 100%; height: 100px; background-color: yellow;} .left{ float: left; width: 100px; height: 200px; background-color: pink;} .center{ width: 300px; height: 200px; background-color: blue;} .right{ width: 100px; height: 200px; background-color: green;} footer{ width: 100%; height: 100px; background-color: black;}
left
에만 float
을 써서 left
값을 주면header{ width: 100%; height: 100px; background-color: yellow;} .left{ float: left; width: 100px; height: 200px; background-color: pink;} .center{ float: left; width: 300px; height: 200px; background-color: blue;} .right{ float: right; width: 100px; height: 200px; background-color: green;} footer{ width: 100%; height: 100px; background-color: black;}
footer
가 header
바로밑에 붙어서 겹쳐보임footer{ width: 100%; height: 100px; background-color: black;}
footer
부분에 clear
를 붙여준다. 그러면 float
을 마지막으로 사용한태그 그다음에 clear
를 보통넣는다. both
는 left
,right
효과를 끈단의미ex)
방지하기위해선 부모의 크기가 가변값이면안됨
항상 고정으로 유지해줘야 안틀어짐
section
으로 감싸줘봄
<header></header> <section> <div class="left"></div> <div class="center"></div> <div class="right"></div> </section> <footer></footer>
section{ width: 1400px; height: 200px; background-color: orange;}
아니면 처음부터 width
를 가변값인 %
를주면 감쌀필요없이 알아서 잘작동한다
.left{ float: left; width: 30%; height: 200px; background-color: pink;} .center{ float: left; width: 20%; height: 200px; background-color: blue;} .right{ float: right; width: 50%; height: 200px; background-color: green;}
section
의 height
값을 없애면 지정했던 orange색이 사라짐.float
을 사용할땐 포지션이 static
이나relative
를 사용해야함.absolute
랑 fixed
는 같이 사용못함.4-1. 실무팁
clear
쓸때 따로 한개 만들어서 쓰자
<div class="left-2"></div> <div class="right-2"></div> <footer></footer>
.left-2{ float: left; width: 100px; height: 150px; background-color: yellow;} .right-2{ float: right; width: 100px; height: 150px; background-color: blue;} footer{ width: 100%; height: 100px; background-color: black;}
여기서 clear
를 사용할때 관례같은거
<div class="clearfix"></div>
.clearfix{ clear: both;}
4-2. 실무팁
overflow
랑 float
같이쓰기
<section> <div class="left-2"></div> <div class="right-2"></div> <div class="clearfix"></div> <footer></footer> </section>
section{ overflow: hidden; width: 800px; background-color: orange;}
overflow: hidden; overflow-y: scroll; overflow-x: scroll;
hidden
은 말그대로 숨기는거x
,y
:scroll
도 말그대로 x,y방향으로 스크롤할수있게 하는거html
<div class="container"> <div class="item one"></div> <div class="item two"></div> <div class="item three"></div> </div>
.container{ display: flex; width: 1000px; border: solid 10px red;} .item { width: 200px; height: 300px;} .one{ background-color: yellow;} .two{ background-color: blue;} .three{ background-color: orange;}
display:flex
는 x축으로 정렬한다 왼쪽부터 시작해서 오른쪽으로
방향을 바꾸고싶으면 flex-direction
기본값은row
(x축),
coulmn
(y축) / 역방향은 뒤에 -reverse
4-1. flex-wrap
flex-wrap: nowrap; flex-wrap: wrap;
container
부분을 wrap
을 활용하면 각각
- nowrap
는 지정해진 수치까지 조절할만큼 레이어를 유지하면서 묶여있음
- warp
는 부모의 width
값에따라 레이어가 틀어짐
4-2. flex-flow
flex-flow: row wrap;
flex-direction
과flex-wrap
을 동시에 입력할때
justify-content: flex-start; justify-content: center; justify-content: end; justify-content: space-between; justify-content: space-around;
align-items: flex-start; align-items: flex-end; align-items: center; align-items: bassline;
여기드가면 금방 일듯,
start
는 시작점 end
는 끝지점 center
는 가운데space-between
은 간격 ,space-around
끝지점에도 간격, bassline
은 각각 모양 가장 아랫줄 기준으로중앙 정렬
<div class="center-1"></div>
.center-1{ width: 300px; height: 300px; background-color: yellow; margin: 0 auto;}
margin
사용 .center-2{ position: relative; width: 300px; height: 300px; background-color: blue; left: 50%; margin-left: -150px;}
position: relative
와 left
50%값을주면 왼쪽면을 기준으로 50%만큼 이동하기때문에 margin-left
로 width의 절반을 당겨온다.