在CSS实现Footer置底的几种方式

html-css011

在CSS实现Footer置底的几种方式,第1张

用简单的CSS实现将FOOTER固定在页面底部,我们通常布局的时候都是头部,内容区域,还有底部,一般都是使用三个div,然后id分别设置为header,content,footer,然后在定义每个div的高度,一般来说,header,footer都是公共的,因为高度,内容一般都是固定的,底部的区域,举个例子:

<html>

<head>

<style>

#header{

width:960px//通过id来控制

height:200px

}

@content{

width:960px//通过id来控制

height:auto //内容区域的高度一般都是auto的

}

#footer{

width:960px//通过id来控制

height:200px

}

</style>

</head>

<body>

<div id='header'>

<p>我是头部区域</p>

</div>

<div id='content'>

<p>我是内容区域</p>

</div>

<div id='footer'>

<p>我是低部区域</p>

</div>

</body>

</html>

用css动态控制footer的位置,我们可以去换个思路,只要给内容区域的高度有变化,我们将footer公共出来给各个文件调用,然后给每个页面的content区域一个不定长的高度,就解决了,如height:auto;这里通过代码来理解:

<html>

<head>

<style>

.headr{

width:900px

height:30px

background:#f00//设置颜色为红色

}

.content{

width:900px

height:auto //给content的高度为auto,这样我们在每个页面中foote的位置就是变化的。

background:#0f0//设置颜色为绿色

}

.footer{

width:900px

height:200px

background:#000

}

</head>

<body>

<div class="headr" > //页头

</div>

<div class="content" > //页面

</div>

<div class="footer" > //页尾

</div>

</body>

</html>