关键词:display: flex,flex: 1,  overflow-y: scroll;

实现:head 和footer 固定,中间body多了滚动,少了撑满; head和footer宽度根据内容撑起,当然你可以自己设置........

小二,上代码!

来喽~~

// html布局
<html>
<body>
<div class="container">
<div class="head">Page Not FoundPage Not FoundPage Not FoundPage Not FoundPage</div>
<div class="body">
<div>orry, but the page you were trying to view does not exist.</div>
<div>shhhhsss</div>
<div>shhhhsss</div>
<div>shhhhsss</div>
<div>shhhhsss</div>
<div>shhhhsss</div>
</div>
<div class="footer">Page Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not Found</div>
</div>
</body>
</html>

关键的css来啦!

 * {
line-height: 1.2;
margin:;
}
html, body {
font-family: sans-serif;
height: 100%;
width: 100%;
}
.container{
display: flex; // 关键, flex布局
flex-direction: column; // 关键,三块主题column摆放。
height: 100vh; // 关键,设置高度为可见高度的100%;
}
.head{
width: 100%;
background: springgreen;
}
.body{
flex:; // 关键, 填充剩余空间
width: 100%;
background: lightyellow;
overflow-y: scroll; // 关键, 超出部分滚动
}
.footer{
width: 100%;
background: goldenrod;
}

附上全部代码,可以自己复制到浏览器中打开,看效果~

<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Page Not Found</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<style> * {
line-height: 1.2;
margin: 0;
} html, body {
color: #888;
font-family: sans-serif;
height: 100%;
width: 100%;
}
.container{
display: flex;
height: 100vh;
flex-direction: column;
}
.head{
width: 100%;
background: springgreen;
}
.body {
background: lightyellow;
width: 100%;
flex:1;
color: black;
overflow-y: scroll;
}
.footer {
background: goldenrod;
width: 100%;
}
.body div {
height: 200px;
width: 300px;
background: greenyellow;
margin: 20px;
}
</style>
</head>
<body>
<div class="container"> <div class="head">Page Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not Found</div>
<div class="body">
<div>orry, but the page you were trying to view does not exist.</div>
<div>shhhhsss</div>
<div>shhhhsss</div>
<div>shhhhsss</div>
<div>shhhhsss</div>
<div>shhhhsss</div>
</div>
<div class="footer">Page Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not FoundPage Not Found</div>
</div>
</body>
</html>

flex 布局实现固定头部和底部,中间滚动布局的更多相关文章

  1. table固定头部,tbody内容滚动

    直觉的感受是修改thead与tbody,尝试了以下几种方法,但均告失败. 1. 将tbody设置为块状元素,然后设置表格的高度与溢出: 1. 将thead设置为绝对定位,然后设置表格的高度与溢出: 1 ...

  2. 设置一个div网页滚动时,使其固定在头部,当页面滚动到距离头部300px时,隐藏该div,另一个div在底部,此时显示;当页面滚动到起始位置时,头部div出现,底部div隐藏

    设置一个div网页滚动时,使其固定在头部,当页面滚动到距离头部300px时,隐藏该div,另一个div在底部,此时显示: 当页面滚动到起始位置时,头部div出现,底部div隐藏 前端代码: <! ...

  3. flex左右布局 左边固定 右侧自适应

    flex左右布局 左边固定 右侧自适应 想要保证自适应内容不超出容器怎么办. 通过为自适应的一侧设置width: 0;或者overflow: hidden;解决. 首先实现标题的布局,也很简单: &l ...

  4. 【转载自W3CPLUS】如何将页脚固定在页面底部

    该文章转载自:W3CPLUS 大漠的文章 http://www.w3cplus.com/css/css-sticky-foot-at-bottom-of-the-page 以下为全文 作为一个Web的 ...

  5. 将HTML页面页脚固定在页面底部(多种方法实现)

    当一个HTML页面中含有较少的内容时,Web页面的footer部分随着飘上来,处在页面的半腰中间,给视觉效果带来极大的影响,接下来为大家介绍下如何将页脚固定在页面底部,感兴趣的朋友可以了解下 作为一个 ...

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

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

  7. HTML5 开发APP(头部和底部选项卡)

    我们开发app有一定固定的样式,比如头部和底部选项卡部分就是公共部分就比如我在做的app进来的主页面就像图片显示的那样 我们该怎么实现呢,实现我们应该建一个主页面index.html,然后建五个子页面 ...

  8. CSS 实现左侧固定,右侧自适应两栏布局的方法

    "左边固定,右边自适应的两栏布局",其中有老生常谈的float方法,BFC方法,也有CSS3的flex布局与grid布局.并非所有的布局都会在开发中使用,但是其中也会涉及一些知识点 ...

  9. 移动端固定头部和固定左边第一列的实现方案(Vue中实现demo)

    最近移动端做一份报表,需要左右滚动时,固定左边部分:上下滚动时,固定头部部分. 代码在Vue中简单实现 主要思路是: a.左边部分滚动,实时修改右边部分的滚动条高度 b.头部和内容部分都设置固定高度, ...

随机推荐

  1. SpringMVC中的拦截器

    1. 自定义拦截器 实现HandlerInterceptor接口 拦截器一: package cn.rodge.ssm.interceptor;import javax.servlet.http.Ht ...

  2. C++相关:C++的IO库

    前言 基本的IO库设施 istream(输入流类型),提供输入操作. ostream(输出流类型),提供输出操作. cin,一个istream对象,从标准输入读取数据. cout,一个ostream对 ...

  3. linux下Clang和gcc的区别

    Clang 比 GCC 编译器的优势: 编译速度更快 编译产出更小 出错提示更友 好,比如 clang 在编译过程可以直接指出相对简单的出错位置以及它 “ 认为 ” 正确的方式 . 内置有静态分析工具 ...

  4. 【转】MySQL int转换成varchar引发的慢查询

    转自http://www.cnblogs.com/billyxp/archive/2013/05/31/3110016.html 最近一周接连处理了2个由于int向varchar转换无法使用索引,从而 ...

  5. jQuery-01:on live bind delegate

    摘自:https://www.cnblogs.com/moonreplace/archive/2012/10/09/2717136.html moonreplace这位大牛的 当我们试图绑定一些事件到 ...

  6. 优雅的玩PHP多进程

    proc_open (PHP 4 >= 4.3.0, PHP 5, PHP 7) proc_open — 执行一个命令,并且打开用来输入/输出的文件指针. 说明¶ resource proc_o ...

  7. 使用Python分析ELF文件优化Flash和Sram空间的案例

    1. 背景 Zephyr项目Flash和Ram空间比较紧张,有着非常强烈的优化需求. 优化的前提是量化标的,那么如何量化Flash和Ram的使用量呢? 在量化之后,首先要对量化结果进行分析,然后采取措 ...

  8. SSIS 检查点

    在SSIS中,检查点实际上是一个记录系统,用于记录控制流中Task组件的执行状态.通过合理地配置Checkpoint,在Package运行出错之后,重新执行Package,可以跳过上一次已经成功执行的 ...

  9. BigDecimal 专题

    //****BigDecimal中传入的double类型的数据,要为String类型,不然得到在BigDecimal仍然是不准确的double数据**** // BigDecimal addend = ...

  10. SQL注入简单介绍

    一.SQL注入概念   1.sql注入是一种将sql代码添加到输入参数中   2.传递到sql服务器解析并执行的一种攻击手法   举例:某个网站的用户名为name=‘admin’.执行时为select ...