display
속성은 요소를 어떻게 표시할지를 선택하고, visibility
속성은 요소를 나타낼지 말지를 결절하는 속성이다. display는 상속이 불가능하고, visibility는 상속이 가능하다.
div, span {
width: 80px;
height: 80px;
margin: 20px;
}
div {
background-color: red;
}
span {
background-color: blue;
display: block;
}
div, span {
width: 80px;
height: 80px;
margin: 20px;
}
div {
background-color: red;
display: inline-block;
}
span {
background-color: blue;
display: block;
}
레이아웃을 배치하거나, 객체를 위치시킬 때 사용할 수 있는 속성이다.
####position: static 포지션의 기본값. html에 정의된 순서대로 브라우저상에 위치하는 것을 말한다. 그렇기때문에 top, left같은 위치값을 주어도 변화가 없다.
####position: relative 원래 위치에서 지정해준 위치만큼 상대적으로 이동한다.
####absolute: 아이템이 담겨있는 부모요소를 기준으로 이동한다.
####fixed: 상자에서 벗어나서 윈도우 내에서 움직인다.
div {
width: 50px;
height: 50px;
margin-bottom: 20px;
background: red;
}
.container {
background-color: black;
left: 20px;
top:20px;
position: relative;
}
.box1 {
background: blue;
left: 20px;
top: 20px;
position: relative;
}
.box2 {
background:wheat;
left: 20px;
top: 20px;
position: absolute;
}
.box3 {
background-color: aquamarine;
left: 20px;
top: 20px;
position: fixed;
}
블록요소를 지정한 위치로 흐르도록 하는 속성을 말한다. 속성에는 left, right, none이 있다.
####clear
float를 지정한 요소의 다음요소는 float의 상속을 받기때문에 clear
를 통해서 요소를 해제시킬 수 있다.
.container {
border: 2px solid blue;
width: 1200px;
margin: auto;
}
header {
border: 2px solid red;
height: 150px;
line-height: 150px;
text-align: center;
}
.inner section {
border: 2px solid green;
width: 400px;
height: 400px;
float: left;
box-sizing: border-box;
}
footer {
border: 3px solid orange;
height: 100px;
clear: left;
}