要求:网页布局中,页脚在底部.内容不够一页时,在底部.内容超过一页时,出现卷动条,页脚也在被挤到底部

1.测试的这个文章介绍的办法   链接: http://www.cnblogs.com/chenyuming507950417/p/4003651.html

经测试,这个办法可以实现要求.

2.测试代码说明

html结构:   

<div class="container">
  <div class="header">头</div>

  <div id="content" class="content">内容</div>

  <div class="footerbox">脚部</div>

</div>

css(关键)

.container {
    position: absolute; /*关键1,容器定位是 absolute,测试发现换成 relative 的,会不行.*/
    min-height: 100%; /*关键2,容器的最小高度为视口高度*/
    /**/
    width: 100%;
}

.content {
    /*这个距离是内容区到footer的距离,防止footer遮住内容区域*/
    padding-bottom: 54px;
}

.footerbox {
    position: absolute; /*关键3,绝对定位,相对于.container*/
    bottom: 0px; /*关键4,定位位置在底部*/
    /**/
    background-color: #000;
    height: 30px;
    line-height: 30px;
    margin: 0;
    padding: 0;
    width: 100%;
}

3.完整测试代码

<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>CSS + DIV 让页脚始终底部</title>
<meta name="generator" content="" />
<style type="text/css">
* {
margin: 0;
padding: 0;
} .container {
position: absolute; /*关键1,容器定位是 absolute,测试发现换成 relative 的,会不行.*/
min-height: 100%; /*关键2,容器的最小高度为视口高度*/
/**/
width: 100%;
} .content {
/*这个距离是内容区到footer的距离,防止footer遮住内容区域*/
padding-bottom: 54px;
} .footerbox {
position: absolute; /*关键3,绝对定位,相对于.container*/
bottom: 0px; /*关键4,定位位置在底部*/
/**/
background-color: #000;
height: 30px;
line-height: 30px;
margin: 0;
padding: 0;
width: 100%;
} .footer {
width: 1080px;
color: forestgreen;
height: 30px;
line-height: 30px;
margin: 0 auto;
} p {
text-align: center;
font-size: 1em;
font-weight: bold;
}
</style>
</head>
<body>
<div class="container">
<div class="header">
底部footer,内容少时自动在最底下,内容多时撑开后到最底下
<button onclick="additem()">增加内容</button>
</div>
<div id="content" class="content"> </div>
<div class="footerbox">
<div class="footer">
这是脚,这是脚,这是脚,这是脚,这是脚,这是脚,这是脚,这是脚,这是脚,这是脚,这是脚,这是脚,这是脚
</div>
</div>
</div>
<script>
for (var i = 0; i < 35; i++) {
var about = document.getElementById("content");
var para = document.createElement("p");
var node = document.createTextNode("这是原有内容" + about.childElementCount);
para.appendChild(node);
about.appendChild(para);
}
function additem() {
var about = document.getElementById("content");
var para = document.createElement("p");
var node = document.createTextNode("新加入一行内容" + about.childElementCount);
para.appendChild(node);
about.appendChild(para)
}
</script>
</body>
</html>

让footer在底部(测试它人方法)的更多相关文章

  1. HTML中footer固定在页面底部的若干种方法

    <div class="header"><div class="main"></div></div> <d ...

  2. 如何将页脚固定在页面底部,4中方法 转载自:W3CPLUS

    原博客地址:http://www.w3cplus.com/css/css-sticky-foot-at-bottom-of-the-page 作为一个Web的前端攻城师,在制作页面效果时肯定有碰到下面 ...

  3. 网页布局中页面内容不足一屏时页脚footer固定底部

    方法一:给html.body都设置100%的高度,确定body下内容设置min-height有效,然后设置主体部分min-height为100%,此时若没有header.footer则刚好完美占满全屏 ...

  4. CSS实现Footer固定底部,超过一屏自动撑开

    方法一:给html.body都设置100%的高度,确定body下内容设置min-height有效,然后设置主体部分min-height为100%,此时若没有header.footer则刚好完美占满全屏 ...

  5. Apache ab测试工具使用方法(无参、get传参、post传参)(转)

    转自Apache ab测试工具使用方法(无参.get传参.post传参) Ab测试工具是apache自带的测试工具,具有简单易上手的特性,下面我总结一下我的使用方法,首先去官方下载apache程序包, ...

  6. LoadRunner测试50人同时登陆下单

    LoadRunner测试50人同时登陆下单 一.LoadRunner简介 LoadRunner,是一种预测系统行为和性能的负载测试工具.通过以模拟上千万用户实施并发负载及实时性能监测的方式来确认和查找 ...

  7. XCode中的单元测试:编写测试类和方法(内容意译自苹果官方文档)

    当你在工程中通过测试导航栏添加了一个测试target之后, xcode会在测试导航栏中显示该target所属的测试类和方法. 这一章演示了怎么创建测试类,以及如何编写测试方法. 测试targets, ...

  8. android 让一个控件按钮居于底部的几种方法

    android 让一个控件按钮居于底部的几种方法1.采用linearlayout布局:android:layout_height="0dp" <!-- 这里不能设置fill_ ...

  9. Randoop测试类和方法(用例自动生成)

    详细使用方法见randoop官网: https://randoop.github.io/randoop/manual/index.html 测试程序之前,先检测下你的Randoop是否配置好: 打开c ...

随机推荐

  1. magent——memcached缓存代理服务器

    memcached分布式缓存 我们使用PHP连接多台memcached服务器,做分布式缓存,实现如下: $memcache = new Memcache; $memcache->addServe ...

  2. 文成小盆友python-num4 装饰器,内置函数

    一 .python 内置函数补充 chr()  -- 返回所给参数对应的 ASCII 对应的字符,与ord()相反 # -*- coding:utf-8 -*- # Author:wencheng.z ...

  3. Activiti工作流学习-----基于5.19.0版本(1)

    该版本的Activiti运行须知: 1.JDK 6+,Eclipse最好是Kepler以上版本. 2.试验功能都有EXPERIMENTAL标注,被标注的部分不应该视为稳定的. 有兴趣的同学可以去了解下 ...

  4. C 带指针样式的时钟

    #include <stdio.h> #include <malloc.h>#include<graphics.h>#include<conio.h> ...

  5. TCP释放连接时为什么time_wait状态必须等待2MSL时间

    为什么上图中的A在TIME-WAIT状态必须等待2MSL时间呢? 第一,为了保证A发送的最后一个ACK报文能够到达B.这个ACK报文段有可能丢失,因而使处在LAST-ACK状态的B收不到对已发送的FI ...

  6. css 画竖着线条

    <p>table控制:<!-- height为横线的粗度,width为长度 --><table width=700>     <tr>    <t ...

  7. 《VIM-Adventures攻略》前言

    本文已转至http://cn.abnerchou.me/2014/03/02/bfdaadb0/ 自从有了计算机,人们就想向其灌输自己的想法. 要想对其输入,自然离不开文本编辑器. 公告:<VI ...

  8. 基于JDK6的JAX-WX为客户端提供XML与JSON格式数据服务,以及客户端采用AXIS调用案例

    1:WebService服务端工程目录如下: 需要第三方jar包:gson-2.2.4.jar\javax.xml.bind.jar\commons-lang-2.5.jar 源码如下: packag ...

  9. cf B. Hungry Sequence

    http://codeforces.com/contest/327/problem/B 这道题素数打表就行. #include <cstdio> #include <cstring& ...

  10. 智能卡安全机制比较系列(五) StarCOS

    StarCOS是捷德公司的推出的智能卡COS,和前面说过的几种COS不同的是,国内的用户对于StartCOS可以说非常熟悉,而且因为握奇.明华.天喻等公司的安全机制都基本上是脱胎于StarCOS,所以 ...