博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
两栏布局的几种方式
阅读量:3947 次
发布时间:2019-05-24

本文共 1966 字,大约阅读时间需要 6 分钟。

两栏布局:左边定宽,右边自适应

在这里插入图片描述

left
right

1. float + margin-left

.left {
float: left; width: 200px; height: 200px; background-color: aquamarine; } .right {
margin-left: 200px; height: 200px; background-color: antiquewhite; }

2. float + overflow:hidden

.left {
float: left; width: 200px; height: 200px; background-color: aquamarine; } .right {
overflow:hidden; height: 200px; background-color: antiquewhite; }
ps:浮动定位注意父标签要清除浮动。

3. 绝对定位

  • 左边方框绝对定位
.con {
position: relative; } .left {
position: absolute; top: 0; left: 0; width: 200px; height: 200px; background-color: aquamarine; } .right {
height: 200px; background-color: antiquewhite; }
  • 右边方框绝对定位
.con {
position: relative; } .left {
width: 200px; height: 200px; background-color: aquamarine; } .right {
position: absolute; top: 0; right: 0; height: 200px; background-color: antiquewhite; }

4. 弹性布局

.con {
display: flex; } .left {
width: 200px; height: 200px; background-color: aquamarine; } .right {
flex: 1; height: 200px; background-color: antiquewhite; }

5. table-cell伪表格布局

.con {
display: table; } .left {
display: table-cell; width: 200px; height: 200px; background-color: aquamarine; } .right {
display: table-cell; height: 200px; background-color: antiquewhite; }

6. inline-block

.left {
display: inline-block; width: 200px; height: 200px; background-color: aquamarine; } .right {
display: inline-block; width:200px; height: 200px; background-color: antiquewhite; }
ps:这种布局两个盒子之间会有空隙,注意清除空隙。

转载地址:http://kchwi.baihongyu.com/

你可能感兴趣的文章
Android 系列 6.29创建在两个活动之间显示的加载屏幕
查看>>
Android的Gradle技巧 1.2配置SDK版本和其他默认值
查看>>
Android的Gradle技巧 1.3从命令行执行Gradle构建
查看>>
Android的Gradle技巧 1.4从Android Studio执行Gradle构建
查看>>
Android的Gradle技巧 1.5添加Java库依赖关系
查看>>
Android的Gradle技巧 1.6使用Android Studio添加库依赖关系
查看>>
Android的Gradle技巧 1.7配置存储库
查看>>
android Collections 排序,
查看>>
Android的Gradle技巧 2.1设置项目属性
查看>>
Android的Gradle技巧 2.2将应用程序从Eclipse ADT移植到Android Studio
查看>>
Android的Gradle技巧 2.3从Eclipse移植应用程序ADT使用Eclipse
查看>>
昂山素季 Aung San Suu Kyi
查看>>
AI 人工智能第一课 从贝叶斯定理开始
查看>>
朴素贝叶斯python实现
查看>>
Logistic回归原理及公式推导
查看>>
并发性与并行性 并发性与并行性
查看>>
惰性求值,可组合和模块化的JavaScript
查看>>
How to Extend Django User Model 如何扩展Django用户模型
查看>>
两个行业的故事:编程语言与富裕国家和发展中国家之间的差异
查看>>
15个用于管理MySQL服务器mysqladmin命令
查看>>