首页 前端知识 使用Flex布局实现盒子的水平垂直居中

使用Flex布局实现盒子的水平垂直居中

2024-05-18 18:05:18 前端知识 前端哥 526 417 我要收藏

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

话不多说,直接上代码。

<!DOCTYPE html>
<html lang="en">
<head>
    <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>

转载请注明出处或者链接地址:https://www.qianduange.cn//article/8787.html
标签
评论
发布的文章

video 自定义视频播放控件

2024-05-26 01:05:25

HTML5 画布绘制海报

2024-05-26 01:05:13

HTML5学习(三)

2024-05-26 01:05:43

大家推荐的文章
会员中心 联系我 留言建议 回顶部
复制成功!