<!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 media="screen">
.box {
width: 200px;
display: table-cell;
background: red;
height: 200px;
word-wrap: break-word;
vertical-align: middle;
}
.box>div {
line-height: 20px;
word-break: break-all;
}
.flex {
display: -webkit-box;
display: -ms-flexbox;
display: flex;
-webkit-box-align: center;
-ms-flex-align: center;
align-items: center;
height: 100px;
background: blue;
}
.flex-1 {
-webkit-box-flex: 1;
-ms-flex: 1;
flex: 1;
}
</style>
</head>
<body>
<!-- table布局垂直居中 -->
<div class="box">
<div>我是多行文字,我要垂直居中1212212111212121212121sdsdsd</div>
</div>
<!-- flex布局垂直居中 -->
<div class="flex">
<div>1231231</div>
<div class="flex-1">我是多行文字,我要垂直居中1212212111212121212121sdsdsd</div>
</div>
</body>
</html>
网友评论