margin , boreder , padding , contents
열린태그랑 닫힌태그 안에있는걸 contents라 생각하면된다.
margin
은 border
기준 바깥,padding
은 border
기준 안쪽,margin
과 border
는 각각 뒤에left
,top
,right
,bottom
을 입력할수도 있지만,margin-left: 100px; margin-top: 100px; margin-right: ; margin-bottom: ; padding-left: 100px; padding-top: 100px; padding-right: ; padding-bottom: ;
top
,right
,bottom
,left
순margin: 100px 0 0 100px; padding: 100px 0 0 100px;
기본적으로 html
이랑 body
는 margin
이랑 padding
값을 가지고 있음.
html,body{ margin: 0; padding: 0;}
margin
과 padding
뒤에 숫자하나만 넣으면 4방향모두에 저값 적용padding
을 쓰면 기본적인 컨텐츠에 +
되는개념이라 모양이 바뀌고 커짐 ,
그걸 방지해보자
box-sizing: border-box;
이럴시 맨처음 기본으로 잡음 크기를 유지하면서 들어감
margin
병합현상<div class="margin-one"></div> <div class="margin-two"></div>
.margin-one{ width: 100%; height: 100px; background-color: yellow; margin-bottom: 100px;} .margin-two{ width: 100%; height: 100px; background-color: blue; margin-top: 50px;}
top
부분을 150px로 바꾸면 아래기준에서 150px만 적용<div class="margin-parent"> <div class="margin-child"></div> </div>
.margin-parent{ width: 300px; height: 300px; background-color: yellow;} .margin-child{ width: 150px; height: 150px; background-color: blue; margin-top: 100px;}
child
값에
position: absolute;
일단 Block
이랑 Inline
을 이해
y축느낌
<h1>Block</h1> <h1>Block</h1> <h1>Block</h1>
x축느낌
<span>Inline</span> <span>Inline</span> <span>Inline</span>
이상태에서 각각에 margin-top
을 넣어도 span
엔 적용안됨
h1 { width: 100px; height: 100px; background-color: yellow; margin-top: 100px;} span { width: 100px; height: 100px; background-color: pink; margin-top: 100px;}
이 상태에서 각각의 속성을 바꾸고 싶을때 display
활용
display: inline; display: block;
양쪽모두의 성격을 갖고싶을때(x축정렬도하고 블록처럼쓰고싶을때
display: inline-block;
vertical-align
해보기
<span class="inline">Inline</span> <span class="inline-block">Inline-Block</span> <img src="https://via.placeholder.com/200">
.inline, .inline-block, img{ vertical-align: middle;}
top
,middle
,bottom
사용block
값에 작성해도 적용안됨.img
태그 는 inline-block
속성을 가지고있음<div class="static-parent"> <div class="static-child"></div> </div>
.static-parent{ width: 300px; height: 300px; background-color: yellow;} .static-child{ position: static; width: 150px; height: 150px; background-color: blue; margin-top: 100px;}
top: 100px;
.static-parent{ width: 300px; /*height: 300px;*/ background-color: yellow;} .static-child{ position: static; width: 150px; height: 150px; background-color: blue;}
<div class="box1"></div> <div class="fixed-parent"> <div class="fixed-child"></div> </div> <div class="box2"></div>
.box1 { width: 300px; height: 200px; background-color: gray;} .fixed-parent { width: 300px; height: 300px; background-color: yellow;} .fixed-child { position: fixed; width: 100px; height: 100px; background-color: blue;} .box2 { width: 300px; height: 2000px; background-color: green;}
fixed
고정된거html,css부분 모두 동일하나 fixed부분이 relative로 변경
box2부분도 삭제
relative일때 마진병합현상이 일어나는가? Yes
top,right,bottom,left를 사용할수있는가? Yes
- 기준점은 최초위치를 기준으로 움직임
자식의 높이값이 부모에게 영항을 주는가? Yes
2차원,3차원 특징을 모두갖고있다.
absolute일때 마진병합현상이 일어나는가? No
top,right,bottom,left를 사용할수있는가? Yes
- 기준점 부모 포지션상태에따라 다름
자식의 높이값이 부모에게 영항을 주는가? No
3차원 특징을 갖고있다.
absolute
는 부모가 어떤 포지션 상태인지에 따라 top,right,bottom,left기준좌표점이 달라짐