栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

粘性页眉和页脚可滚动内容

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

粘性页眉和页脚可滚动内容

方法1-Flexbox

它适用于已知和未知的高度元素。确保设置外股利

height:100%;
和重置默认
margin
body

html, body {  height: 100%;  margin: 0;}.wrapper {  height: 100%;  display: flex;  flex-direction: column;}.header, .footer {  background: silver;}.content {  flex: 1;  overflow: auto;  background: pink;}<div >  <div >Header</div>  <div >    <div >Content</div>  </div>  <div >Footer</div></div>

方法2-CSS表

对于已知和未知高度元素。它也可以在包括IE8在内的旧版浏览器中使用。

html, body {  height: 100%;  margin: 0;}.wrapper {  height: 100%;  width: 100%;  display: table;}.header, .content, .footer {  display: table-row;}.header, .footer {  background: silver;}.inner {  display: table-cell;}.content .inner {  height: 100%;  position: relative;  background: pink;}.scrollable {  position: absolute;  left: 0; right: 0;  top: 0; bottom: 0;  overflow: auto;}<div >  <div >    <div >Header</div>  </div>  <div >    <div >      <div >        <div >Content</div>      </div>    </div>  </div>  <div >    <div >Footer</div>  </div></div>

方法3-
calc()

如果页眉和页脚固定高度,则可以使用CSS

calc()

html, body {  height: 100%;  margin: 0;}.wrapper {  height: 100%;}.header, .footer {  height: 50px;  background: silver;}.content {  height: calc(100% - 100px);  overflow: auto;  background: pink;}<div >  <div >Header</div>  <div >    <div >Content</div>  </div>  <div >Footer</div></div>

方法4-所有百分比

如果页眉和页脚的高度已知,并且它们也是百分比,则只需执行简单的数学运算即可将它们的高度设为100%。

html, body {  height: 100%;  margin: 0;}.wrapper {  height: 100%;}.header, .footer {  height: 10%;  background: silver;}.content {  height: 80%;  overflow: auto;  background: pink;}<div >  <div >Header</div>  <div >    <div >Content</div>  </div>  <div >Footer</div></div>


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/442550.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号