display:table-cell 居中及其使用
2017-09-15 11:26
288 查看
一、例子:
And
二、table-cell的使用:http://www.zhangxinxu.com/
<html> <meta charset="utf8"> <style> .Absolute-Center { display: table-cell; width: 100px; height: 100px; border:1px solid red; text-align:center; vertical-align:middle; } </style> <body> <div class="Absolute-Center"> <p>居中</p> </div> </body> </html>
-----------------起作用
<html> <meta charset="utf8"> <style> .outer{ width:300px; height:500px; border:1px solid red; position:relative; } .Absolute-Center { display: table-cell; position:absolute; margin:auto; top:0px; bottom:0px; left:0px; right:0px; width: 100px; height: 100px; border:1px solid red; text-align:center; vertical-align:middle; } </style> <body> <div class="outer"> <div class="Absolute-Center"> <p>居中</p> </div> </div> </body> </html>
---------------无效 原因:
position: absolute; display: table-cell;equals
display: block; position: absolute;. 1#
And
vertical-alignonly applies to
inline/
table-cellelements.
修改:
<div class="outer"> <div class="center"> <div class="center-inner"> <p>居中</p> </div> </div> </div>
.outer{ width:300px; height:500px; border:1px solid red; position:relative; } .center { position: absolute; margin: auto; top:0px; bottom:0px; left:0px; right:0px; width: 100px; height: 100px; border:1px solid red; } .center-inner { display: table; height: 100%; width: 100%; } .center p { display: table-cell; text-align:center; vertical-align:middle; }
二、table-cell的使用:http://www.zhangxinxu.com/
相关文章推荐
- 使用display:table-cell 和 vertical-align:middle 不定宽高图片居中于容器
- JTable的使用,以及使用JTextArea和DefaultTableCellRenderer达到居中或者多行显示的效果
- 实现div垂直居中的display:table-cell方法示例介绍
- Display: table-cell实现img、文字垂直居中
- 使用display:table-cell元素部分出现空白缝隙的结解决
- css - display:table-cell的使用
- 未知大小的图片在div中水平垂直居中(拒绝使用table-cell)
- 利用display:table-cell让文字垂直居中(无论元素多少行)
- 父级div使用display:table-cell;vertical-align:middle会出现空隙。
- 使层垂直居中的display:table-cell方法,多浏览器兼容
- tableview——设置cell的文字居中和透明度
- 我所知道的几种display:table-cell的应用
- 基于CSS属性display:table的表格布局的使用
- CSS让未知高度div的内容垂直居中(table-cell 和 负margin)
- swift tableView registerCell基于协议的实现和使用
- html使用display:inline-block实现标签右对齐,值左对齐效果。和设置div宽度,并居中显示。嵌套div的里层div文字居中显示
- 一个简洁的图片垂直居中,不需要hack,不需要table-cell
- IOS 只有在TableViewController里面才可以使用TableView的static cell
- tableView以及cell的使用