display:table布局总结
1. table布局方式

2. table布局实际应用
效果:
代码:
<!DOCTYPE html>
<html lang="en"> <head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
/*CSS Table*/
.table { display: table; }
.table-fixed { table-layout: fixed; }
.table-row { display: table-row; }
.table-cell { display: table-cell; }
.table-colgroup { display: table-column-group; }
.table-caption { display: table-caption; }
.table-col { display: table-column; }
.table-body { display: table-row-group; }
.table-header { display: table-header-group; }
.table-footer { display: table-footer-group; }
.table-vt { vertical-align: top; }
.table-vm { vertical-align: middle; }
.table-vb { vertical-align: bottom; }
/*CSS Table*/
html,
body { height: 100%;margin: 0; padding: 0; background: #333;}
div.demo1 { width: 100%;height: 200px; }
.box1 { background: #6D5CAE; }
.box2 { background: #48B0F7; }
.box3 { background: #10CFBD; }
h3 { padding-left: 20px;color: #fff; }
.demo2 { width: 400px;height: 300px;}
.demo2 div.table-header-group {padding: 5px 20px;background: #10CFBD;}
.demo2 .main {height: 100%;background: #48B0F7;}
.demo2 div.table-footer-group {padding: 5px 20px;background: #10CFBD;}
.demo3 {width: 400px;height: 300px;background: #10CFBD;}
.demo4 {width: 400px;height: 300px;background: #10CFBD;text-align: center;}
.center-box {width: 100px;height:100px;background: #6D5CAE;display: inline-block;}
.header{font-size:30px;} /*列表布局,等空隙*/
.grid {
display: table;
border-spacing: 4px;
}
.row {
display: table-row;
}
.image {
display: table-cell;
width: 240px;
height: 300px;
background-color: lightsalmon;
vertical-align: top;
text-align: center;
}
</style>
</head> <body>
<h3>子容器自动平分宽度(即使设置宽度,也会进行自动等分,自适应父容器的宽度)</h3>
<div class="table demo1">
<div class="box1 table-cell">1</div>
<div class="box2 table-cell">2</div>
<div class="box3 table-cell">3</div>
</div> <h3>垂直三行,中间自适应</h3>
<div class="table demo2">
<div class="header table-header-group">Table Header</div>
<div class="main table-row">自动占满剩余空间</div>
<div class="table-footer-group">Table Footer</div>
</div> <h3>垂直居中对齐</h3>
<div class="table demo3">
<div class="table-cell table-vm">
<div class="center-box">123</div>
</div>
</div> <h3>水平居中对齐</h3>
<div class="demo4" style="text-align:left;">
<div class="table" style="margin:0 auto">
<div class="center-box">123</div>
</div>
</div> <h3>水平居中对齐2</h3>
<div class="demo4" style="text-align:left;">
<span class="center-box table" style="margin:0 auto">123345678</span>
</div> <h3>列表布局,border-spacing实现等空隙</h3>
<div class="grid">
<div class="row">
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
</div>
<div class="row">
<div class="image"></div>
<div class="image"></div>
<div class="image"></div>
</div>
</div>
</body> </html>
3. table布局其他应用
1. 实现两端对齐布局,使用两个table-cell,分别text-align:left和text-align:right,由于要额外套两个容器,所以不是较好的方法
2. 实现等高布局,具体可以参考等高布局
3. 实现两栏自适应布局,具体可以参考自适应布局
4. table布局的注意点
1. display: table时padding会失效
2. display: table-row时margin、padding同时失效
3. display: table-cell时margin会失效,padding有效,高度有效
4. display: table-cell时float, position:absolute会失效,不用同时使用
参考:http://ghmagical.com/article/page/id/s1x7vzL6Z2Sz
https://blog.csdn.net/Xiaotongbiji/article/details/79851288
https://blog.csdn.net/Bessicxie/article/details/78572424
https://blog.csdn.net/Doulvme/article/details/79015264
https://blog.csdn.net/huangbaokang/article/details/82183084
display:table布局总结的更多相关文章
- [转]基于display:table的CSS布局
当IE8发布时,它将支持很多新的CSS display属性值,包括与表格相关的属性值:table.table-row和table-cell,它也是最后一款支持这些属性值的主流浏览器.它标志着复杂CSS ...
- CSS display:table属性用法- 轻松实现了三栏等高布局
display:table:此元素会作为块级表格来显示(类似 <table>); display:table-cell属性指让标签元素以表格单元格的形式呈现,类似于td标签.目前IE8+以 ...
- 基于CSS属性display:table的表格布局的使用
项目改造中遇到DIV+CSS实现的table,新需求需要在表格使用单元格合并,网上调查返现CSS display:table实现的table表格,没有单元格的属性和样式,经过一番思考,曲折现实了单元格 ...
- css Table布局:基于display:table的CSS布局
两种类型的表格布局 你有两种方式使用表格布局 -HTML Table(<table>标签)和CSS Table(display:table 等相关属性). HTML Table是指使用原生 ...
- 使用display:table使两栏布局高度相等
两栏布局大家应该经常用了,但是遇到坑爹的要两栏的高度对齐的话要怎么办呢? <!DOCTYPE html> <html> <head> <meta charse ...
- css display:table圣杯布局
圣杯布局指的是一个网页由页眉,3等高列(2个固定侧栏和中心内容主体)和贴在页面底部的页脚组成. 主要思路是对整个容器使用地上diaplay:table 的css规则,然后分别对页眉页脚使用displa ...
- 使用display:table来解决一些问题
一直有,多栏的需求,当然用table布局,很快就做完了.不怎么喜欢用table,刚开始使用display:table,但是有一条老是不能达到我的效果,那就是有一行不固定宽度的时候,就不知道怎么处理,今 ...
- css table 布局
使用CSS表格 CSS表格能够解决所有那些我们在使用绝对定位和浮动定位进行多列布局时所遇到的问题.例如,“display:table;”的CSS声明能够让一个HTML元素和它的子节点像table元素一 ...
- 记录display:table的使用
兼容性:不兼容IE7 1.左右对齐 <!DOCTYPE html> <html lang="en"> <head> <meta chars ...
随机推荐
- System.Threading
线程:定义为可执行应用程序中的基本执行单元. 应用程序域:一个应用程序内可能有多个线程. 上下文:一个线程可以移动到一个特定的上下文的实体 导入命名空间: //得到正在执行这个方法的线程 Thread ...
- 《javascript 学习笔记》
注释 1. // This is an in-line comment. 2. /* This is a multi-line comment */ 七种data types(数据类型) undef ...
- 零基础快速入门SpringBoot2.0教程 (三)
一.SpringBoot Starter讲解 简介:介绍什么是SpringBoot Starter和主要作用 1.官网地址:https://docs.spring.io/spring-boot/doc ...
- 博学谷-数据分析matplotlib
博学谷-数据分析 python数学学科的基础 机器学习课程的基础 1.1 介绍 1.2 jupyter和conda 1.3 matplotlib from matplotlib import pypl ...
- 井字游戏 人机对战 java实现
package com.ecnu.Main; /** * 主函数触发游戏 */public class MainApplication { public static void main(String ...
- css分层,实现遮罩底层弹出新窗口里可以操作,最下层能看到单不能操作
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 初学puppet
初学puppet puppet是什么? puppet是一个开源的软件自动化配置和部署工具,很多大型IT公司均在使用puppet对集群中的软件进行管理和部署. Puppet简介 Puppet的目录是让管 ...
- 【bug】【yii】配置log时,报错 Setting read-only property: yii\web\Application::log
Setting read-only property: yii\web\Application::log 配置放在了 components 外面,应该放在里面
- Laravel — homestead 配置多站点
一.homestead.yaml 配置 homestead.yaml 文件配置sites,如下 sites: - map: homestead.test to: /home/vagrant/Code/ ...
- Spark MLlib(下)--机器学习库SparkMLlib实战
1.MLlib实例 1.1 聚类实例 1.1.1 算法说明 聚类(Cluster analysis)有时也被翻译为簇类,其核心任务是:将一组目标object划分为若干个簇,每个簇之间的object尽可 ...