垂直居中的相关CSS 类
记录下一段相关代码 方便日后查阅调用。
<!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>
.flex,
.vertical-center {
display: -webkit-flex;
display: flex;
}
.float>.left {
float: left;
}
.float>.right {
float: right;
}
.vertical-center {
-webkit-flex-wrap: nowrap;
flex-wrap: nowrap;
-webkit-align-content: center;
align-content: center;
align-items: center;
}
.v-center-flex {
align-self: center;
}
.v-center-table-cell {
display: table-cell;
vertical-align: middle;
}
</style>
</head>
<body>
<div class=" vertical-center " style=" height:300px;width: 300px; background-color: brown;">
程序员怎么才能保护好眼睛?
</div>
<br />
<div class=" flex" style=" height:300px; width: 300px; background-color: brown;">
<div class="v-center-flex ">程序员怎么才能保护好眼睛?</div>
</div>
<br />
<div class=" vertical-center " style=" height:300px;width: 300px; background-color: brown;">
<div class="v-center-table-cell ">程序员怎么才能保护好眼睛?</div>
</div>
</body>
</html>