css如何让页脚固定在底部


当前第2页 返回上一页

CSS

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

html,body {

  margin: 0;

  padding:0;

  height: 100%;

}

#container {

  min-height:100%;

  height: auto !important;

  height: 100%; /*IE6不识别min-height*/

  position: relative;

}

#header {

    background: #ff0;

    padding: 10px;

}

#page {

    width: 960px;

    margin: 0 auto;

    padding-bottom: 60px;/*等于footer的高度*/

}

#footer {

    position: absolute;

    bottom: 0;

    width: 100%;

    height: 60px;/*脚部的高度*/

    background: #6cf;

    clear:both;

}

/*=======主体内容部分省略=======*/

从css代码中,我们看到,页面主体 page 设置了一个 padding-bottom ,并且与 footer 的高度是一致的。这里不能使用 margin-bottom 来代替 padding-bottom 。

这个方案有一个缺点: footer 必须要固定高度, page 必须要设置一个大于等于这个高度的 padding-bottom 。如果 footer 不是固定高度的,或者需要对footer做自适应,那么这种方案就不太适合了。

相关推荐:CSS教程

以上就是css如何让页脚固定在底部的详细内容,更多文章请关注木庄网络博客

返回前面的内容

相关阅读 >>

css中设置边框可以用哪些属性

css如何让块无间隙

css如何实现给div添加滚动并隐藏滚动条

css怎么给button设置阴影

jq如何判断css是否存在

css如何实现阴影效果

css怎么清除空白

一分钟了解css的主要功能

css怎么做半圆

css如何实现图片抽屉式效果

更多相关阅读请进入《css》频道 >>




打赏

取消

感谢您的支持,我会继续努力的!

扫码支持
扫码打赏,您说多少就多少

打开支付宝扫一扫,即可进行扫码打赏哦

分享从这里开始,精彩与您同在

评论

管理员已关闭评论功能...