欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

块元素居中方式

程序员文章站 2022-04-25 14:42:26
...
<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        .wrap {
            position: relative;
            width: 300px;
            height: 300px;
            background-color: pink;
        }
        
        .box1 {
            position: absolute;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            margin: auto;
            width: 100px;
            height: 100px;
            background-color: yellow;
        }
    </style>
</head>

<body>
    <div class='wrap'>
        <div class="box1"></div>
    </div>
</body>

</html>

块元素居中方式

相关标签: DIV + CSS