flex布局 div盒子居中

时间:2022-07-22
本文章向大家介绍flex布局 div盒子居中,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。
直接上代码吧
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>邮箱验证测试</title>
    <style type="text/css">

        *{
            padding: 0;
            margin: 0;
        }
        body,html{
            width: 100%;
            height:100%;
        }
        .top{
            display: flex;
            height: 100%;
            width: 100%;
            justify-content: center;
            align-items: center;

        }
        .cen{
            width: 250px;
            height: 250px;
            background: rgba(110,150,150,0.2);
             border-radius: 10px;
        }
        input {
            border-radius: 5px;
        }
    </style>
</head>
<body>
# 这里是外层div,开启flex 布局
<div class="top">
# 这里是内层div,接收top flex 弹性盒子设置属性。
    <div class="cen" >
<form method="post" action="">
       用户名:<input type="text" name="username"><br>
    密码:<input type="text" name="password"><br>
    验证邮箱:<input type="text" name="mall"><br>

{#    内容 :<input type="text" name="text"><br>#}
    <input type="submit" value="验证">

</form>
        <hr>
        <div >
        <form method="get" action="/sigin">
            输入激活码:<input type="text" name="code">
            <input type="submit" value="提交">

        </form>
    </div>


         <hr>
        <div >
        <form method="get" action="/deng">
            账号:<input type="text" name="username"><br>
            密码:<input type="text" name="password"><br>
            <input type="submit" value="提交">

        </form>
    </div>


        </div>


</div>


</body>
</html>