<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>42度空间-未知高度的块元素垂直居中</title>
    <style>
        .parent {
            height: 140px;
            position: relative;
            border: 2px dashed #f69c55;
        }
        .child {
            position: absolute;
            top: 50%;
            transform: translateY(-50%);
            background: black;
            color: #fff;
            padding: 1rem;
            width: 12rem;
        }
    </style>
</head>
<body>
<div class="parent">
    <div class="child">世界上有 10 种人,懂二进制的和不懂二进制的。</div>
</div>
</body>
</html>