底部按鈕固定
方案一:絕對定位
優點:相容性較好,可以使用任何場景(推薦)
<!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:
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:
}
.bg{
height: 100%;
}
.footer{
height: 100px;
position: absolute;
z-index: 10;
bottom: 0;
left: 0;
right: 0;
text-align: center;
color: white;
background-color:
}
</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:
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:
}
.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:
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:
}
.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>
複製程式碼