移動端結構上下固心猿意馬中心自順應,本家兒要運用的css為flex。
經由過程flex的屬性flex:1; 實現中心區域拉伸,獲得自順應結果。
第一步:界說本家兒體布局
界說一個div中包含三個小div
年夜div樣式:
display: flex;
flex-direction:column;
第二步:上下固心猿意馬
頂部與底部樣式 固心猿意馬定位 position:fixed;
頂部top: 0px;
底部bottom: 0px;
第三步:中心自順應
中心自順應區域樣式
flex:1;
overflow: scroll;
第四步:要在樣式表中添加 html,body{height:100%;}
原因:讓中心區域有個高度可以擔當
第五步:完整代碼
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>百度經驗</title>
<style type="text/css">
*{
margin: 0;
padding: 0;
}
html,body{height:100%;}
body{
font-family: 微軟雅黑;
background-color: #f4f4f4;
}
.demon{
display: flex;
flex-direction:column;
height: 100%;
}
.fixed{
width: 100%;
line-height: 45px;
font-size: 16px;
background-color: #0088ee;
color: #fff;
text-align: center;
position: fixed;
}
.fixTop{
top: 0px;
}
.fixBottom{
bottom: 0px;
}
.container2{
flex:1;
margin: 55px 10px ;
background-color: #fff;
overflow: scroll;
}
</style>
</head>
<body >
<div>
<div class="fixed fixTop">
<span>頂部文字</span>
</div>
<div>
<p>hahaha</p>
</div>
<div class="fixed fixBottom">
<span>底部文字</span>
</div>
</div>
</body>
</html>
0 篇文章
如果覺得我的文章對您有用,請隨意打賞。你的支持將鼓勵我繼續創作!