.button {
position : static; / 기준이 x / default값 좌표설정x
position : relative; / 기준이 나 / : 원래위치부터 좌표변경
position : absolute; / 기준이 바로 위 부모 / : position:relative 가지고있는 부모에게 달려듬
position : fixed; / 기준이 브라우저 창 (viewport) / : 화면이 스크롤되어도 해당 버튼이 고정됨
}
top, left, bottom, right 라는 속성을 사용하면
요소의 상하좌우 위치를 변경할 수 있다.
하지만 이 좌표속성을 사용하려면 position 속성이 필요하다.
<style type="text/css">
div{
border:5px solid tomato;
margin:10px;
}
</style>
<div id="other">other</div>
<div id="parent">
parent
<div id="me">me</div>
</div>
#me{
left:100px;
top: 100px;
}
이번에는 위의 예제에서
<style type="text/css">
div{
border:5px solid tomato;
margin:10px;
}
</style>
<div id="other">other</div>
<div id="parent">
parent
<div id="me">me</div>
</div>
#me{
position: relative;
left:100px;
top: 100px;
}
이번에는
<style type="text/css">
#parent, #other{
border:5px solid tomato;
}
#me{
background-color: black;
color:white;
}
</style>
<div id="other">other</div>
<div id="parent">
parent
<div id="me">me</div>
</div>
#me{
background-color: black;
color:white;
position: absolute;
left:0px;
top:0px;
}
#parent{
position: relative;
}
#me{
background-color: black;
color:white;
position: absolute;
left:0px;
top:0px;
}
#grand{
position: relative;
}
#parent{
position: relative;
}
#me{
background-color: black;
color:white;
position: absolute;
left:0px;
top:0px;
}
<div id="other">other</div>
<div id="grand">
<div id="parent">
parent
<div id="me">me</div>
</div>
</div>
이 경우,
#parent, #other{
border:5px solid tomato;
}
#me{
background-color: black;
color:white;
position: fixed;
left:0px;
top:0px;
}
#large{
height: 1000px;
background-color: tomato;
}
<div id="other">other</div>
<div id="parent">
parent
<div id="me">me </div>
</div>
<div id="large">large</div>