CSS居中布局总结【转】
居中布局
<div class=”parent”>
<div class=”child”>demo</div>
</div>
1.水平居中
1> 方案一 inlink-block+text-align
.child {display:inlink-block;}
.parent {text-align:center;}
优点:兼容性好
缺点:子元素宽高不可设置
2> 方案二 table+margin
.child {display:table; margin:0 auto;}
优点:只需要设置child(自己)
3> 方案三 absolute+transform
.parent {position:relative;}
.child {position:absolute;left:50%;transform:translateX(-50%);}
优点:子元素不会对其他元素产生影响
缺点:兼容性问题
4> 方案四 flex+justify-content
.parent {display:flex;justify-content:center;}
优点:只需设置parent节点
或者设置为
.parent {display:flex;}
.child {margin:0 auto;}
缺点:flex低版本ie不支持
2.垂直居中
1> 方案一 table-cell+vertical-align
.parent {display:table-cell;vertical-align:middle;}
优点:只需设置父节点,兼容性好
2> 方案二 absolute+transform
.parent {position:relative;}
.child {position:absolute;top:50%;transform:translateY(-50%);}
优点:子元素不会对其他元素产生影响
缺点:兼容性问题
3> 方案三 flex+align-items
.parent {display:flex;align-items:center;}
优点:只需设置父节点
缺点:兼容性问题
3.水平和垂直均居中
1> 方案一 inline-block+text-align+table-cell+vertical-align
.parent {text-align:center;display:table-cell;vertical-align:middle;}
.child {display:inline-block;}
2> 方案二 absolute+transform
.parent {position:relative;}
.child { position:absolute;left:50%;top:50%;transform:translate(-50%,-50%);}
3> 方案三 flex+justify-content+align-items
.parent {display:flex;justify-content:center;align-items:center;}
思路:了解属性值特性,分解问题。
转载自:http://www.cnblogs.com/xiaohangzi/p/6090995.html
CSS居中布局总结【转】的更多相关文章
- CSS居中布局方案
基本结构 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF- ...
- CSS居中布局总结
居中布局 <div class="parent"> <div class="child">demo</div> </d ...
- 详解 CSS 居中布局技巧
水平居中元素: 通用方法,元素的宽高未知 方式一:CSS3 transform .parent { position: relative; } .child { position: absolute; ...
- 详解CSS居中布局技巧
本文转自:https://zhuanlan.zhihu.com/p/25068655#showWechatShareTip一.水平居中元素: 1.通用方法,元素的宽高未知方式一:CSS3 transf ...
- CSS 居中布局
来源:http://www.cnblogs.com/QianBoy/p/8539077.html 水平居中 1)使用inline-block+text-align 原理:先将子框由块级元素改变为行内块 ...
- css居中布局的几种方式
一.水平居中 若是行内元素,则直接给其父元素设置text-align: center即可 若是块级元素,则直接给该元素设置margin: 0 auto即可 若子元素包含浮动元素,则给父元素设置widt ...
- CSS居中布局
一:水平居中方案: 1.行内元素 设置 text-align:center 2.定宽块状元素 设置 左右 margin 值为 auto 3.不定宽块状元素 a:在元素外加入 table 标签(完整的, ...
- css 居中布局方案
position(transform css3 有些浏览器不兼容) <article id="one"> <section id="section&q ...
- CSS基础布局--居中对齐,左侧定宽右侧自适应
CSS页面布局是web前端开发的最基本的技能,本文将介绍一些常见的布局方法,涉及到盒子布局,column布局,flex布局等内容.本文中,你可以看到一些水平垂直居中的方法,左侧固定宽度,右侧自适应的一 ...
随机推荐
- 如何使用C自带的qsort快速排序
/ you can write to stdout for debugging purposes, e.g. // printf("this is a debug message\n&quo ...
- PHP 获取中国时间,即上海时区时间
/** * 获取中国时间,即上海时区时间 * @param <type> $format * @return <type> */ function getChinaTime($ ...
- 交叉编译中的build、host和target
build.host和target 在交叉编译中比较常见的一些参数就是build.host和target了,正确的理解这三者的含义对于交叉编译是非常重要的,下面就此进行解释 --build=编译 ...
- Postman 发送http请求工具
http://donglegend.com/2016/10/28/Postman/ Postman 发现一款发送Web API & HTTP 请求的工具,没错,就是Postman.推荐给大家, ...
- Apache Rewrite匹配问号的问题
在写RewriteRule准备匹配url中的问号及后面的参数时,怎么弄都无法成功.正则的写法经过测试是正确的,问号也已经转义\?,可还是不行. 百度查询了下,RewriteRule 不会去匹配问号?后 ...
- git 教程(15)--分支管理策略
通常,合并分支时,如果可能,Git会用Fast forward模式,但这种模式下,删除分支后,会丢掉分支信息. 如果要强制禁用Fast forward模式,Git就会在merge时生成一个新的comm ...
- 核型SVM
(本文内容和图片来自林轩田老师<机器学习技法>) 1. 核技巧引入 如果要用SVM来做非线性的分类,我们采用的方法是将原来的特征空间映射到另一个更高维的空间,在这个更高维的空间做线性的SV ...
- FileZillaFTP使用教程
FileZillaServer.exe服务启动和关闭程序 FileZilla Server Interface.exe 服务 管理程序 配置ftp服务器的用户名,密码,目录,目录读写权限 启动File ...
- resin 安装配置
resin (下载免费版 4) 前提:已经安装了Java运行环境,resin的安装需要jdk的支持 一.安装 1.cd /usr/local/src wget http://www.caucho. ...
- session超时时间设置方法
session超时时间设置方法 由于session值之前没有设置,以至于刚登录的网站,不到一分钟就超时了,总结了一下,原来是session过期的原因,以下是设置session时间的3个方法: 1. 在 ...