css:实现div元素垂直居中

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>垂直居中</title>
    <style>
        .container {
            position: absolute;
            width: 400px;
            height: 200px;
            background-color: orange;
            left: 50%;
            top: 50%;
            transform: translate(-50%,-50%);
        }
    </style>
</head>
<body>
<div class="container"></div>
posted @ 2020-07-22 23:01  珊迪·奇克斯  阅读(120)  评论(0编辑  收藏  举报