基础//页面布局——两栏布局3


一、题目

根据题目给出你的答案。
(上高度固定,下自适应)
题目:上高度固定为150px,下自适应。

二、我的代码详情

https://codepen.io/janmie-cjm/pen/QWNBYgP

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>页面布局-两栏布局3</title>
  <style>
    html *{
      margin: 0;
      padding: 0;
    }
    body{
      background: #ffccee;
      width: 100%;
      height: 100%;
    }
  </style>
</head>
<body>
<!-- 上高度固定150px,下自适应 -->
  <!-- 1-绝对定位 -->
  <!-- <section>
    <style>
      .top1 {
        background: #aee;
        width: 100%;
        height: 150px;
        top: 0;
        position: absolute;
      }
      .bottom1 {
        background: #eaa;
        width: 100%;
        height: 100%;
        top: 150px;
        position: absolute;
      }
    </style>
    <article class="wrapper1">
      <div class="top1">我是上栏</div>
      <div class="bottom1">我是下栏</div>
    </article>
  </section> -->

  <!-- 2-flexbox -->
  <!-- <section class="wrapper2">
    <style>
      body,section,article {
        display: flex;
        flex-direction: column;
        height: 100vh;
        width: 100%;
      }
      .top2 {
        background: #aee;
        width: 100%;
        height: 150px;
      }
      .bottom2 {
        background: #eaa;
        width: 100%;
        flex: 1;
      }
    </style>
    <article>
      <div class="top2">我是上栏</div>
      <div class="bottom2">我是下栏</div>
    </article>
  </section> -->

  <!-- 3-table -->
  <!-- <section>
    <style>
      .wrapper3 {
        display: table;
        width: 100%;
        height: 100vh;
      }
      .wrapper3>div {
        display: table-row;
      }
      .top3 {
        background: #aee;
        width: 100%;
        height: 150px;
      }
      .bottom3 {
        background: #eaa;
        width: 100%;
      }

    </style>
    <article class="wrapper3">
      <div class="top3">我是上栏</div>
      <div class="bottom3">我是下栏</div>
    </article>
  </section> -->

  <!-- 4-grid -->
  <section>
    <style>
      .wrapper4 {
        display: grid;
        grid-template-columns: auto;
        grid-template-rows: 150px auto;
        width: 100%;
        height: 100vh;
      }
      .top4 {
        background: #aee;
        width: 100%;
      }
      .bottom4 {
        background: #eaa;
        width: 100%;
      }

    </style>
    <article class="wrapper4">
      <div class="top4">我是上栏</div>
      <div class="bottom4">我是下栏</div>
    </article>
  </section>
</body>
</html>

三、总结

  1. 本题目的解决方案有哪些?
    绝对定位 / flexbox / 表格布局 / 网格布局 ;

  2. 各方案优缺点?
    1)绝对定位
    优:简单
    缺:脱离文档流,需结合BFC应用,代码较多
    2)flexbox
    优:简单快捷,兼容性好
    3)表格布局
    优:兼容性较好
    缺:每一列高度会同时变化;表格需先渲染,延迟页面生成速度
    4)网格布局
    优:可实现多行多列的二维复杂操作,兼容性较好,简化代码

  3. 兼容性好的方案有?
    flexbox、网格布局

注意!!!上下布局撑开整个页面,一般最外层高度设为height = 100vh才行。


*代码尚存在很多不足,望提出不同的意见,互相交流。*
ColumnLayoutHelper是CSDN开发的一种用于实现栏格布局的辅助工具。栏格布局是一种常见的页面布局,通过将内容分为多列来展示信息,使得页面更加整齐和易读。 ColumnLayoutHelper提供了一系列方法和属性,用于指定列数、列间距、行间距等布局相关的参数。使用该工具可以快速实现栏格布局,并且可以灵活地调整布局的样式和效果。 例如,可以通过设置列数和间距属性来控制栏格布局的样式: ``` ColumnLayoutHelper layoutHelper = new ColumnLayoutHelper(); layoutHelper.setColumnCount(2); // 设置为两列 layoutHelper.setPadding(10, 10, 10, 10); // 设置内边距 layoutHelper.setMargin(10, 10, 10, 10); // 设置外边距 layoutHelper.setAspectRatio(1.5f); // 设置列的宽高比例 ``` 然后,将需要展示的内容添加到栏格布局中: ``` ColumnLayoutHelper.ColumnLayoutView view1 = new ColumnLayoutHelper.ColumnLayoutView(); view1.setColumnSpan(1); // 设置占据的列数 view1.setLayoutView(view1); // 设置视图 ColumnLayoutHelper.ColumnLayoutView view2 = new ColumnLayoutHelper.ColumnLayoutView(); view2.setColumnSpan(1); view2.setLayoutView(view2); layoutHelper.addView(view1); layoutHelper.addView(view2); ``` 最后,将ColumnLayoutHelper应用到布局中,即可实现栏格布局的效果: ``` VirtualLayoutManager layoutManager = new VirtualLayoutManager(context); RecyclerView recyclerView = new RecyclerView(context); recyclerView.setLayoutManager(layoutManager); DelegateAdapter delegateAdapter = new DelegateAdapter(layoutManager); delegateAdapter.addAdapter(new SingleLayoutAdapter(context, layoutHelper)); recyclerView.setAdapter(delegateAdapter); ``` 通过使用ColumnLayoutHelper,开发者可以方便地实现栏格布局,提升页面的展示效果和用户体验。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值