html5怎么让盒子居中_css怎么让盒子居中

(73) 2024-07-19 17:01:03

PC端盒子居中方式一

<!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>盒子完全居中方式一</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        div {
            width: 100px;
            height: 200px;
            background: rgb(189, 243, 209);
            position: fixed;
            top: 50%;
            left: 50%;
            margin-top: -100px;
            margin-left: -50px;
        }
    </style>

</head>
<body>
    <div></div>
</body>
</html>

PC端盒子居中方式二

<!DOCTYPE html>
<html lang="en">
THE END

发表回复