JSFiddle - React, Tailwind, and code Playground
by cj1406942109
HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>块级元素垂直居中</title>
</head>
<body>
<div class="parent">
<span class="child">
我是行内元素,我要垂直居中
</span>
</div>
</body>
</html>
CSS
.parent {
width: 500px; /* 为了显示方便,与本文知识点无关 */
background-color: teal; /* 为了显示方便,与本文知识点无关 */
height: 300px; /* 为了展示需要,不一定要设置该属性 */
display: -webkit-box;
}
.child {
background-color: tomato;
color: #fff;
margin: auto 0;
}