定宽高的水平垂直居中
来源:互联网 发布:中国云计算大会 2017 编辑:程序博客网 时间:2024/05/22 08:19
绝对定位和负magin值
效果预览
<div class="parent"> <div class="child"></div></div>
div.parent { width: 400px; height: 400px; background: #EDEDED; position: relative;}div.child { width: 200px; height: 200px; background: green; position: absolute; left: 50%; top: 50%; margin-left: -100px; margin-top: -100px;}
绝对定位 + left/right/bottom/top + margin
div.parent { width: 400px; height: 400px; background: #EDEDED; position: relative;}div.child { width: 200px; height: 200px; background: green; position: absolute; left: 0; top: 0; bottom: 0; right: 0; margin: auto;}
flex
这种方法在不定宽高的时候也可以使用,页面结构如上,效果预览
div.parent { width: 400px; height: 400px; background: #EDEDED; display: flex; justify-content:center; align-items: center; }div.child { width: 300px; height: 200px; background: green;}
绝对定位+transform
这个方法在不定宽高中也使用过,页面结构不变,效果预览
div.parent { width: 400px; height: 400px; background: #EDEDED; position: relative; }div.child { width: 100px; height: 100px; position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); background: green;}
table-cell + vertical-align + inline-block
先提醒一下,vertical-align
的值是middle
,而不是center
页面结构不变,效果预览
div.parent { width: 400px; height: 400px; background: #EDEDED; display: table-cell; text-align: center; vertical-align: middle;}div.child { width: 100px; height: 100px; display: inline-block; background: green;}
阅读全文
0 0
- 定宽高的水平垂直居中
- 各种各样的水平垂直居中
- 元素的水平垂直居中
- 文本的水平垂直居中
- 垂直水平居中的方式
- 水平居中与垂直居中的区别
- 水平居中与垂直居中的区别
- CSS的水平居中与垂直居中
- 水平居中,垂直居中
- 水平居中垂直居中
- 其中的各种居中(水平居中,垂直居中,水平垂直居中)
- html元素水平居中、垂直居中、水平垂直居中于其父级元素的方法
- 元素的水平居中,垂直居中以及同时水平,垂直居中方法
- html元素水平居中、垂直居中、水平垂直居中于其父级元素的方法
- 多行文字的垂直水平居中
- css垂直水平居中的整理
- css垂直水平居中的整理
- css div的水平、垂直同时居中
- poj 2227 The Wedding Juicer
- idea can't resolve the symbol "servlet"
- HDU5533 Dancing Stars on Me(计算几何)
- ReactNative之弹出窗
- Codeforces
- 定宽高的水平垂直居中
- RedisTemlale操作List测试类
- js SyntaxError: unterminated string literal
- UESTC
- Android Https相关完全解析 当OkHttp遇到Https
- CocoaPods管理三方开源库
- ReactNative杂项整理
- UML里面的常用分析手段
- day11