本文介绍: 在日常开发中,我们经常会制作登录注册框,一般这种框都是水平垂直于整个页面的,像这种的话一般都是用flex布局书写,因为这样最简洁方便。话不多说,直接上代码

日常开发中,我们经常会制作登录注册框,一般这种框都是水平垂直于整个页面的,像这种的话一般都是用flex布局书写,因为这样最简洁方便。

话不多说,直接上代码

<!DOCTYPE html>
<html lang="en"&gt;
<head&gt;
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>使用flex布局实现盒子垂直居中</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        body{
            height: 100vh;
            display: flex;
            justify-content: center;
            align-items: center;
        }
        div{
            width: 200px;
            height: 200px;
            background-color: aqua;
        }
    </style>
</head>
<body>
    <div></div>
</body>
</html>

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注