垂直居中

垂直水平居中

```css
.sup {
    width: 200px;
	height: 200px;
    display: table-cell;
    vertical-align: middle;
}
.sub {
    width: 100px;
	height: 100px;
    margin: 0 auto;
}

代码示范

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>垂直居中</title>
<style type="text/css">
.sup {
width: 200px;
height: 200px;
background-color: red;
/*可以控制内容/子级垂直排列方式*/
display: table-cell;
/*设置垂直排列方式*/
vertical-align: middle;
}
.sub {
width: 100px;
/*height: 100px;*/
background-color: orange;
margin: 0 auto;
}
</style>
</head>
<body>
<div class="sup">
<div class="sub">多行文本多行文本多行文本多行文本多行文本</div>
</div>
</body>
</html>

 
posted @ 2018-09-28 15:02  不沉之月  阅读(70)  评论(0编辑  收藏  举报