移动端布局上下固定中间自适应

 时间:2026-02-14 12:10:35

1、第一步:定义主体结构

定义一个div中包含三个小div

大div样式:

display: flex;

flex-direction:column; 

移动端布局上下固定中间自适应

2、第二步:上下固定

顶部与底部样式 固定定位 position:fixed; 

顶部top: 0px;

底部bottom: 0px; 

移动端布局上下固定中间自适应

3、第三步:中间自适应

中间自适应区域样式

flex:1;  

overflow: scroll;

移动端布局上下固定中间自适应

4、第四步:要在样式表中添加 html,body{height:100%;} 

原因:让中间区域有个高度可以继承

移动端布局上下固定中间自适应

移动端布局上下固定中间自适应

5、第五步:完整代码

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

         hahaha   

    </div> 

    <div class="fixed fixBottom"> 

        <span>底部文字</span>

    </div>  

</div>   

</body>

</html>  


  

移动端布局上下固定中间自适应

  • 2017狂龙之吼怎么获得
  • DNF地下城格兰迪福利篇神秘商人加百利
  • dnf90起源男机械装备搭配?dnf机械元首毕业装备?
  • DNF木罐的龙人之塔任务怎么做
  • win10怎么判断是否适用Hyper-V虚拟机
  • 热门搜索
    西雅图旅游 香港 旅游 山东旅游政务网 峨嵋山旅游 四川 旅游 到敦煌旅游 旅游风光 去美国旅游注意事项 三天旅游 甘肃 旅游