首页 > 其他分享 >Flex布局,和position布局,实现上下固定中间部分滚动

Flex布局,和position布局,实现上下固定中间部分滚动

时间:2024-02-02 10:58:04浏览次数:29  
标签:Flex 50px flex 布局 bottom height background position line

Flex布局实现上下固定中间部分滚动:

<div class="parent">
    <div class="header">header -- 固定</div>
    <div class="content">
      <p>content -- 滚动</p>
      <p>内容部分</p>
      <p>内容部分</p>
      <p>内容部分</p>
      <p>内容部分</p>
        ......
    </div>
    <div class="footer">footer -- 固定</div>
</div>

<style>
  .parent{
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
  }

  .header {
    width: 100%;
    height: 50px;
    line-height: 50px;
    background: #b6efff;
    text-align: center;
  }

  .content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
  }

  p {
    height: 70px;
    line-height: 70px;
    border-bottom: 1px solid #ccc;
  }

  .footer {
    height: 50px;
    line-height: 50px;
    background: #b6efff;
  }

</style>

传统布局实现上下固定中间部分滚动:

<div class="parent">
    <div class="top">top</div>
    <div class="center">
      <p>center1</p>
      <p>center2</p>
      <p>center3</p>
      <p>center...</p>
      <p>center.n</p>
    </div>
    <div class="bottom">bottom</div>
</div>

<style>
  * {
    margin: 0;
    padding: 0;
  }

  .parent {
    background: blanchedalmond;
    height: 100vh;
    overflow-y: hidden;
  }

  .top,
  .bottom {
    width: 100%;
    height: 50px;
    line-height: 50px;
    font-size: 18px;
    background: seagreen;
    text-align: center;
    position: fixed;
  }

  .bottom {
    bottom: 0;
  }

  p {
    height: 50px;
    line-height: 50px;
    border: 1px dashed darkcyan;
  }

  .center {
    height: calc(100vh - 100px);
    position: relative;
    top: 50px;
    background: #ccc;
    overflow-y: scroll;
  }
</style>

标签:Flex,50px,flex,布局,bottom,height,background,position,line
From: https://www.cnblogs.com/cn-oldboy/p/18002737

相关文章

  • 布局算力新基建,九章云极DataCanvas公司赋能AI产业高质量发展
    近日,WIM2023(WorldInnovatorsMeet,世界创新者年会)在北京盛大举行,九章云极DataCanvas联合创始人尚明栋受邀出席论坛,并作“AI基础软件加速产业智能化升级”主题演讲。WIM2023由亿欧、中关村国家自主创新示范区展示中心、中关村会展与服务产业联盟联合主办,以“穿越波动韧性前行”为......
  • Flex 布局教程:语法篇
    Flex布局教程:语法篇作者:阮一峰日期:2015年7月10日网页布局(layout)是CSS的一个重点应用。布局的传统解决方案,基于盒状模型,依赖display属性+position属性+float属性。它对于那些特殊布局非常不方便,比如,垂直居中就不容易实现。2009年,W3C提出了一种新的方案----Fl......
  • 弹性布局,flex-direction: column;盒子宽度不随着上面盒子变化
    需求大盒子里面的上面盒子药固定宽度下面的盒子要随着自己文字内容宽度,要把下面盒子变成行内块样式这样就不随着上面盒子变化了.nameInfo{//大盒子                  margin-left:28upx;                  display:flex;......
  • mybatis-flex框架多数据源缺陷以及IN和exists的区别及应用
    mybatis-flex框架多数据源情况下,跨数据源查询,因为没法用在一个queryWrapper查询,所以会需要分步查询,就需要使用到子查询。众所周知,子查询速度比join查询慢,所以多数据源有该缺陷。in关键字,和exist关键字,这两个是相反的。区别及应用场景in和exists的区别:如果子查询......
  • Android开发笔记[8]-基于Compose布局的开屏页
    摘要基于Compose布局的开屏页,显示进度条;自动跳转到其他页面.关键信息AndroidStudio:ElectricEel|2022.1.1Patch2Gradle:distributionUrl=https://services.gradle.org/distributions/gradle-7.5-bin.zipjvmTarget='1.8'minSdk21targetSdk33compileSdk33开......
  • Hugging Face创始人分享:企业如何在ChatGPT浪潮下实现战略布局
    HuggingFace创始人兼首席执行官ClemDelangue在IBM一年一度的THINK大会中研讨了当前人工智能发展趋势,特别是ChatGPT模型以及其对行业的影响。他的演讲还涉及到一个关键的议题,在ChatGPT这样的通用模型出现后,企业如何在人工智能领域找到自己的定位与价值。他的观点不仅深刻反映了......
  • css实现子元素整体居中,最后一行靠左。grid布局
    <divclass="container"><divclass="item">1</div><divclass="item">2</div><divclass="item">3</div><divclass="item">4</div><divclass......
  • 在写布局样式的时候,什么时候命名为area,什么时候为container,什么时候为wrapper,什么时
    在编写布局样式时,对于类名的选择如area、container、wrapper和box等具有语义的名称是非常重要的,它们可以帮助开发者和维护者更好地理解HTML结构与功能。以下是一些最佳实践以及何时使用这些类名的理由:container:通常用于包裹整个页面或特定区块的主要内容容器。理由:这......
  • 浮动布局小练习
    分析如下实现代码<!DOCTYPEhtml><htmllang="en"><head><metacharset="UTF-8"><metaname="viewport"content="width=device-width,initial-scale=1.0"><title>Document</ti......
  • AndroidStudio 编辑xml布局文件卡死问题解决
    之前项目编写的都是正常,升级AndroidStudio后编辑布局文件就卡死,还以为是AndroidStudio文件。其实不然,我给整个项目增加了版权声明。所以全部跟新后,布局文件也增加了版权声明。估计AndroidStudio在解析布局文件时候因为有版权声明的原因导致卡死,所以删除版权声明就可以了。可以......