인스펙터에서 보면 바디가 분명 화면보다 짧은데도 바디에 백그라운드 컬러를 주면 전체 화면에 적용된다. 왜인지 궁금해서 찾아보니까 의외로 역사적인 얘기에 가까웠다. 아래 스택오버플로우 답변에 기반하여 찾아보면서 조금 살을 붙여봤다.
Stackoverflow: Why does changing the body's background color change the entire page's background?
옛날옛날에.. document
자체의 백그라운드를 설정할 수 있게 해주는 document.bgcolor
라고 하는 것이 있었는데, 2000년 11월 발표된 DOM Level 2 HTML
에서 deprecated 되었다. 이를 대체할 수 있었던 document.body.bgColor
또한 HTML 4.01
에 추가된 CSS style 사용 장려를 위해서 deprecated 되었다.
이렇게 없어진 document
전용 bgcolor
를 대신하기 위해서 마련한 것이 document.body.style.backgroundColor
이다.
따라서 body
의 실제 크기와 상관없이, document.body.style.backgroundColor
라는 속성은 document
의 배경 색상을 바꾸게 된다.
https://developer.mozilla.org/en-US/docs/Web/API/Document/bgColor
솔직한 회고 잘 보고 가요~~