阅读 709

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

底部按钮固定

方案一:绝对定位

优点:兼容性较好,可以使用任何场景(推荐)

image

<!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>


复制代码

计分助理

关注下面的标签,发现更多相似文章
评论