핵심1. position 속성이 무엇인가?
핵심2. position 속성을 사용하는 이유?
핵심3. position 속성의 종류와 무엇을 할 수 있는가?
position 속성은 HTML에 사용되는 style 태그의 속성 중 하나로, 문서 상에 태그를 구성하는 요소를 배치하는 방법을 정의합니다. 쉽게 말해 태그의 구성 요소를 개발자가 배치하고자 하는 위치, 간격, 형태로 구성할 때 사용하는 속성입니다.
사용자가 각 태그의 위치, 간격을 일일이 지정하는 것은 웹 페이지가 복잡해질수록 더욱 어려워집니다. 이에 문서의 레이아웃에 따라, 각각의 태그들을 태그들의 관계 속에서 어떤 형태로 보이게 할지를 position 속성으로 정리하는 것입니다.
static
position: static;
right: 0;
bottom: 0;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
width: 100%;
height: 150px;
background-color: rgb(75, 75, 75);
}
relative
#main_container{
position: relative;
margin-top: 150px;
width: 1200px;
height: 100%;
background-color: #ccc;
}
absolute
많은 개발자들이 absolute를 사용하기를 꺼려한다! WHY??
- 레이아웃의 예측의 어려움
- 디자인 변경의 어려움
- z-index 속성의 남용의 위험
코드를 입력하세요
fixed
#header{
position: fixed;
top: 0;
left: 0;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
height: 150px;
border-bottom: 1px solid red;
color: white;
font-size: 50pt;
font-family: 'Gamja Flower', cursive;
text-align: center;
text-shadow: 2px 2px 1px black, -1px -1px 0px black, 1px -1px 0px black, -1px 1px 0px black;
background-size: cover;
z-index: 100;
}
sticky
#floating{
position: sticky;
top: 200px;
left: 80%;
display: flex;
flex-direction: column;
justify-content: flex-start;
width: 300px;
background-color: rgb(177, 255, 255);
float: right;
}
#위의 예시 코드는 첨부된 url에 저장된 HTML의 코드이므로, 참고 바랍니다.