底部按钮固定方案(移动端)

底部按钮固定

方案一:绝对定位
优点:兼容性较好,可以使用任何场景(推荐)

<!DOCTYPE html>
<html lang="en" dir="ltr">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
		<title></title>
		<style type="text/css">
    a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font-size:100%;font-family:'Microsoft Yahei,Heiti SC';font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:'';content:none}table{border-collapse:collapse;border-spacing:0}b,em,h1,h2,h3,h4,h5,h6,i,strong{font-style:normal;font-weight:400}a{text-decoration:none}a:active{color:#000}img{border:0}table{border-collapse:collapse;border-spacing:0}.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}.hairlines div{border-width:.5px}
		html{
			height: 100%;
		}
		body{
			height: 100%;
		}
		.wrapper{
			position: absolute;
	    z-index: 10;
	    top: 0;
	    left: 0;
	    right: 0;
	    overflow-y: auto;
	    bottom: 100px;
		}
		.content{
			height: 200px;
			background-color: #bbbbbb;
		}
		.bg{
			height: 100%;
		}
		.footer{
			height: 100px;
			position: absolute;
z-index: 10;
bottom: 0;
left: 0;
right: 0;
text-align: center;
color: white;
background-color: #E6454A;
		}
    </style>
	</head>
	<body>
		<div class="bg">
			<div class="wrapper">
				<div class="content">content</div>
			<div class="content">content</div>
			<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
	<div class="content">content</div>
	<div class="content">content</div>
<div class="content">content</div>
			</div>
			<div class="footer"></div>

		</div>
	</body>
</html>

复制代码
方案三:fixed定位
优点:实现简单,缺点:ios8等一些浏览器上会有跳动。

<!DOCTYPE html>
<html lang="en" dir="ltr">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

		<title></title>
		<style type="text/css">
		a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font-size:100%;font-family:'Microsoft Yahei,Heiti SC';font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:'';content:none}table{border-collapse:collapse;border-spacing:0}b,em,h1,h2,h3,h4,h5,h6,i,strong{font-style:normal;font-weight:400}a{text-decoration:none}a:active{color:#000}img{border:0}table{border-collapse:collapse;border-spacing:0}.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}.hairlines div{border-width:.5px}
		html{
			height: 100%;
		}
		body{
			height: 100%;
		}
		.footer{
			height: 100px;
			position: fixed;
			z-index: 10;
			bottom: 0;
			left: 0;
			right: 0;
			text-align: center;
			color: white;
			background-color: #E6454A;
		}
		.content{
			background-color: grey;
			height: 100px;
		}
		</style>
	</head>
	<body>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="content">content</div>
		<div class="footer"></div>
	</body>
</html>


复制代码
方案三:flex
优点:实现简单,缺点:较低版本浏览器对flex不支持。

<!DOCTYPE html>
<html lang="en" dir="ltr">
	<head>
		<meta charset="utf-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">

		<title></title>
		<style type="text/css">
		a,abbr,acronym,address,applet,article,aside,audio,b,big,blockquote,body,canvas,caption,center,cite,code,dd,del,details,dfn,div,dl,dt,em,embed,fieldset,figcaption,figure,footer,form,h1,h2,h3,h4,h5,h6,header,hgroup,html,i,iframe,img,ins,kbd,label,legend,li,mark,menu,nav,object,ol,output,p,pre,q,ruby,s,samp,section,small,span,strike,strong,sub,summary,sup,table,tbody,td,tfoot,th,thead,time,tr,tt,u,ul,var,video{margin:0;padding:0;border:0;font-size:100%;font-family:'Microsoft Yahei,Heiti SC';font:inherit;vertical-align:baseline}article,aside,details,figcaption,figure,footer,header,hgroup,menu,nav,section{display:block}body{line-height:1}ol,ul{list-style:none}blockquote,q{quotes:none}blockquote:after,blockquote:before,q:after,q:before{content:'';content:none}table{border-collapse:collapse;border-spacing:0}b,em,h1,h2,h3,h4,h5,h6,i,strong{font-style:normal;font-weight:400}a{text-decoration:none}a:active{color:#000}img{border:0}table{border-collapse:collapse;border-spacing:0}.clearfix:after{content:".";display:block;height:0;clear:both;visibility:hidden}.hairlines div{border-width:.5px}
		html{
			height: 100%;
		}
		body{
			height: 100%;
		}
		.wrap{
			display: flex;
			flex-direction: column;
			height: 100%;
		}
		.footer{
			height: 100px;
			width: 100%;
			text-align: center;
			color: white;
			background-color: #E6454A;
		}
		.content{
			overflow-y: auto;
	    flex-shrink: 1;
	    flex-grow: 1;
		}
		</style>
	</head>
	<body>
		<div class="wrap">
			<div class="content">

				sssssss
				ssss
			</div>
			<div class="footer"></div>
		</div>

	</body>
</html>


复制代码

转载于:https://juejin.im/post/5bc31f69e51d4539701e97ba

  • 2
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值