๋ณธ๋ฌธ ๋ฐ”๋กœ๊ฐ€๊ธฐ
Before. 2021

min-height:100% ๋ฅผ ์ด์šฉํ•ด์„œ footer๋ฅผ ํ™”๋ฉด์•„๋ž˜์— ๊ณ ์ •ํ•˜๊ธฐ

by ๋น™๊ณ ๊ตฌ๋ง›ํƒ• 2012. 9. 18.

/* html */

<body>

<div id="header">

<h3>header</h3>

</div>

<div id="container">

<div class="cont">

<h3>container</h3>

</div>

</div>

<div id="footer">

<h3>footer</h3>

</div>

</body>


/* css */


html, body{width:100%height:100%}

html{width:100%;height:100%}

body{width:100%;height:100%}


html๊ณผ body์— height:100%๋ฅผ ์ ์šฉ์‹œํ‚ต๋‹ˆ๋‹ค.


#header{width:100%;height:50px;position:relative;z-index:20;overflow:hidden;background-color:#fcc}


๋ฐฑ๊ทธ๋ผ์šด๋“œ์ปฌ๋Ÿฌ๋Š” ์ž˜ ๋จนํ˜”๋Š”์ง€ ํ™•์ธ์„ ์œ„ํ•œ๊ฒƒ์ผ๋ฟ์ž…๋‹ˆ๋‹ค.

๋†’์ด๊ฐ’์„ ๊ผญ header์— ์ •ํ•ด์ฃผ์–ด์•ผ๋˜๋ฉฐ position์ด ํ•„์ˆ˜๋กœ ์žˆ์–ด์•ผ์ง€ container๊ฐ€ ์˜ฌ๋ผ์™”์„๋•Œ z-index๋ฅผ ์ด์šฉํ•ด์„œ container์œ„์— ์˜ฌ๋ผ์˜ฌ์ˆ˜์žˆ์Šต๋‹ˆ๋‹ค.

(z-index์˜ ๊ฐ’์€ ๋ฌด์กฐ๊ป€ container๋ณด๋‹ค ๋†’์•„์•ผ๋จ)



#container{width:100%;min-height:100%;position:relative;z-index:10;margin:-50px 0 -50px 0;background-color:#FF6}


min-height์˜ ๊ฐ’์„ 100%๋กœ ์ง€์ •ํ•ด์ฃผ๊ณ  position์„ ์ด์šฉํ•ด์„œ z-index๋ฅผ ๋‚ฎ์ถฅ๋‹ˆ๋‹ค.

margin์˜ ๊ฒฝ์šฐ top -50์€ header์˜ ๋†’์ด๊ฐ’  bottom -50์€ footer์˜ ๋†’์ด๊ฐ’์„ ๋„ฃ์–ด์ค๋‹ˆ๋‹ค.


.cont{padding-top:50px}


container๊ฐ€ header์˜ ์•„๋ž˜์— ์œ„์น˜ํ•ด ์žˆ๊ธฐ๋•Œ๋ฌธ์— ๊ธ€์„ ์ •์ƒ์ ์œผ๋กœ ๋ณด์—ฌ์ฃผ๊ธฐ ์œ„ํ•ด cont์— padding-top:50์„ ์ค๋‹ˆ๋‹ค(50์€ header์˜ ๋†’์ด๊ฐ’)



#footer{width:100%;height:50px;position:relative;z-index:20;overflow:hidden;background-color:#CCF}


footer๋˜ํ•œ header์™€ ๊ฐ™์ด ๋†’์ด๊ฐ’๋“ฑ์„ ๋„ฃ์–ด์ฃผ๋ฉด



์•„๋ž˜์™€๊ฐ™์€ ํ™”๋ฉด์ด ๋ณด์—ฌ์ง€๊ฒŒ๋ฉ๋‹ˆ๋‹ค.










์ฐธ๊ณ ๋กœ 
*html #container{height:100%;}๋ฅผ ๋„ฃ์ง€์•Š์œผ๋ฉด IE6์—์„œ ์ •์ƒ์ ์œผ๋กœ ์ถœ๋ ฅ๋˜์ง€์•Š์Šต๋‹ˆ๋‹ค.




์ฐธ๊ณ )http://html.nhncorp.com/index.php?mid=textyle&category=5857&vid=blog&document_srl=634