당신이 고정 된 경계 또는 동적 국경을 찾고 계십니까? 코드의 문제점은 W3C 박스 모델입니다. 기본 모델에서는 패딩, 여백 및 테두리가 요소 크기에 추가됩니다. 그래서 당신의 코드에서 정말로 말하고있는 것은 "상자를 100 % 만든 다음 10px 분량의 테두리를 추가하십시오"입니다.
일반적으로 상자 모델을 수동으로 전환하는 것이 쉬운 변경 사항이지만, 불행히도 해당 속성은 height: 100%
과 잘 맞지 않습니다. 따라서 몇 가지 옵션이 있습니다 :
1) 고정 테두리를 찾고있는 경우, 이것은 좋은 속임수입니다 : http://css-tricks.com/body-border/ 2) 동적 테두리가 필요한 경우, 테두리를 추가 높이로 처리해야합니다 추가.
<div id="container">
<div id="header"></div>
<div id="content"></div>
<div id="footer"></div>
</div>
jsfiddle 여기
html,body { height:100%; padding: 0; margin: 0; }
#container {
min-height:100%;
border-right: 5px solid #000;
border-left: 5px solid #000;
position: relative; /* relative postion so we can absolutely position footer within it */
}
#header {
height: 100px;
border-top: 5px solid #000;
background-color: red;
}
#content { padding: 0 0 100px 0; } /*padding must be equal to the height of the footer*/
#footer {
height: 100px;
border-bottom: 5px solid #000;
background-color: blue;
position: absolute;
bottom: 0;
width: 100%; /* with absolute position, a width must be declared */
}
HTML : 기본적으로 http://jsfiddle.net/Qw2cb/
그래, 2012 년에는 존재하지 않았어. 좋은 대답 tho –
사실 나는 알고있다. 어쩌면 다른 사람에게 도움이 될 것 같은 생각! – daneczech