首页 > 其他分享 >css-常用布局-基础的五种

css-常用布局-基础的五种

时间:2022-10-24 19:34:27浏览次数:75  
标签:常用 color width 五种 background left calc css 200px

三栏布局:

如果不考虑高度,即用内容填充高度的话,是可以用inline-block和calc()实现布局的。但适用性差。
float和position的兼容性好,但float会用到calc属性影响兼容性。
calc和flex的兼容性都有一定问题。
grid是未来的发展趋势所以兼容性拉跨也很合理吧,哈哈

body
<body>
    <div class="out">
        <div class="item left"></div>
        <div class="item mid"></div>
        <div class="item right"></div>
    </div>
</body>

float实现

点我查看代码
        .item{
            float: left;
            height: 400px;
        }
        .left,.right{
            width: 200px;
            background-color: antiquewhite;
        }
        .mid{
            width: calc(100% - 400px);
            background-color: aqua;
        }

重点:使用了calc计算了中间宽度

absolute实现

点击查看代码
        .out{
            position: relative;
        }
        .item{
            top:0;
            position: absolute;
            height: 400px;
        }
        .left{
            background-color:antiquewhite;
            width: 200px;
            left: 0;
        }
        .right{
            background-color: antiquewhite;
            width: 200px;
            right: 0;
        }
        .mid{
            width: calc(100% - 400px);
            left: 200px;
            background-color: aqua;
        }

重点:同样可使用calc计算宽度,但也可以通过ps的方法达到更好的兼容性
ps. mid也可以通过left:200px;right:200px实现

flex实现

点击查看代码
        .out{
            display: flex;
            height: 400px;
        }
        .left,.right{
            width: 200px;
            background-color: antiquewhite;
        }
        .mid{
            flex:auto;
            background-color: aqua;
        }

用flex:auto实现自适应

table实现

点击查看代码
        .out{
            display: table;
            height: 400px;
            width: 100%;
        }
        .item{
            display:table-cell;
        }
        .left,.right{
            width: 200px;
            background-color: antiquewhite;
        }
        .mid{
            width: calc(100% - 400px);
            background-color: aqua;
        }

用calc实现自适应

grid布局

点击查看代码
        .out{
            display: grid;
            grid-template-rows: 400px;
            grid-template-columns: 200px auto 200px;
        }
        .left,.right{
            background-color: antiquewhite;
        }
        .mid{
            background-color: aqua;
        }

用grid-template-rows的auto属性实现自适应


本随笔参考b站前端小夏老师有关布局视频进行实践,仅做个人记录,十分感谢前辈们的分享

标签:常用,color,width,五种,background,left,calc,css,200px
From: https://www.cnblogs.com/badpear/p/16821949.html

相关文章

  • IDEA 的常用插件
     ......
  • Git常用命令总结
    1、(先进入项目文件夹)通过命令gitinit把这个目录变成git可以管理的仓库gitinit2、把文件添加到版本库中,使用命令gitadd.添加到暂存区里面去,不要忘记后面的小数点“.”......
  • Eclipse常用设置汇总
     设置编码:.    设置字体:   依次展开 Window->Preferences->Java->CodeStyle->Formatter  在右边窗口中找到Edit ·找到LineWrapping ·在Maximumlinewidth......
  • Ubuntu 安装以及常用命令
    下载系统镜像文件到Ubuntu官网下载对应想安装的.iso系统镜像文件,以下ubuntu-20.04.4-desktop-amd64.iso为例下载地址:DownloadUbuntuDesktop|Download|Ubuntuapt命......
  • 【Linux】3.常用命令
    1.关机&重启命令shutdown-hnow立刻进行关机shutdown-h11分钟后关机shutdown-r now立刻重新启动计算机halt关机reboot重启计算机sync......
  • List接口的常用方法和遍历方式
    packagecom.msb.test01;importjava.util.ArrayList;importjava.util.Iterator;/***@author:liu*日期:16:47:13*描述:IntelliJIDEA*版本:1.0*/p......
  • kubernetes 客户端KubeClient使用及常用api
    KubeClient是kubernetes的C#语言客户端简单易用,KubeClient是.NETCore(目标​​netstandard1.4​​​)的可扩展KubernetesAPI客户端,github地址:​​https://github.com/tin......
  • linux常用命令3
    cat显示文件内容cat-ntextfile1>textfile2输入,将textfile1文件内容输入到textfile2中,会覆盖对应行号内容#cat>mm.txt<<EOF输入,EOF为分隔符more分页显示文本文件......
  • 【前端】总结一下前端css样式规范
    (总结一下前端css样式规范)前端样式CSS规范通用规范//badpadding-bottom:0px;margin:0em;//goodpadding-bottom:0;margin:0;如果CSS可以做到,就不要使用......
  • Colletion接口常用方法
    packagecom.msb.test01;importjava.util.ArrayList;importjava.util.Arrays;importjava.util.Collection;importjava.util.List;/***@author:liu*日......