position:relative 관련 질문
중독된
2023.04.01
position:relative 관련 질문
relative는 상대위치이고
absolute는 절대위치라고 배웠어요
즉
absolute는 body의 0,0을 기준으로 한다고 알고 있어요.
style type=text/css
#box1 { width:150px; height:150px; background-color:red;
position:relative; margin:auto;}
#box2 { width:150px; height:150px; background-color:green;
position:absolute; float:left;}
/style
/head
body
div id=box1boxA/div
div id=box2boxB/div
/body여기서보면
boxA가 가운데로 가면
boxB는 body의 0,0 기준이 되어서
화면 왼쪽 모서리에 붙어야 하는거 아닌가요?
boxA와 boxB 모두 absolute로 해서 보면,
세로로
ㅁ
ㅁ
이런식으로 나오는데
boxB는 원래 저 위치가 boxA가 먼저 생성되었기 때문에 boxB의 위치는 원래 저기인건가요?
boxArelative하고 가운데 정렬시켜서 위치이동하면
boxB의 위치가 body의 0,0으로 이동할줄 알았는데 그게 아니네요질문이 좀 이상하지만
boxB의 원래 위치는 결과화면처럼 저기인가요?
boxA가 먼저 생성되었기때문에 저기일 수밖에 없는건가요?