栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

sticky footer 的几种实现方法

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

sticky footer 的几种实现方法

方法一:利用padding和margin

利用margin

DOM 结构

content
sticky footer
CSS html,body{ height:100%; } .content{ min-height:100%; margin-bottom:-100px; } .footer,.content:after{ height:100px; }

利用padding,会多一层DOM结构

DOM

	
CSS .wrap{ box-sizing:border-box; min-height:100%; padding-bottom:100px; } main{ min-height:100%; } footer{ margin-bottom:-100px; height:100px; }

方法二: 利用calc() 属性
.content{
	height: calc(100% - 100px);
}

方法三: flex
DOM 结构 同上
CSS
html{
	height:100%;
}
html body{
	min-height:100%;
	display:flex;
	flex-direction:column;
	
}
.content{
	flex:1; 
}
.footer{
	height:100px;
	flex:none;  
}

方法四:gird

缺点:兼容性不好

body{
	display:grid;
	grid-template-rows:80px auto 100px;
}

方法五: 绝对定位
DOM结构(随意)

	i am content



CSS
html{
	min-height:100%;
	position:relative;
}
body{
	margin-bottom:100px;
}
.footer{
	position:absolute;
	height:100px;
	width:100%;
	bottom:0;
}

方法六:table

兼容所有主流浏览器

DOM 结构

	
CSS html,body,.wrap{ height:100%; } .wrap{ display:table; } header,footer,.main{ display:block; display:table-row; } header,footer{ height:1 }

暂时整理这么多

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

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

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