<!DOCTYPE HTML>
<html>
<head>
    <meta charset="utf-8">
    <title>42度空间-未知宽高元素水平垂直居中</title>
    <style>
        .parent {
            height: 140px;
            position: relative;
            border: 2px dashed #f69c55;
        }
        .child {
            padding: 10px;
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%, -50%);
            color: #fff;
            background: black;
        }
    </style>
</head>
<body>
<div class="parent">
    <div class="child">当你试图解决一个你不理解的问题时,复杂化就产成了。</div>
</div>
</body>
</html>