用calc 实现水平垂直居中

2020-09-30  本文已影响0人  宏_4491
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<style>
    .box{
        position: relative;
        height: 400px;
        width: 400px;
        background-color: pink;

    }
    .box2{
        height: 100px;
        width: 100px;
        background-color: skyblue;
        position: absolute;
        left: calc(50% - 50px);
        top: calc(50% - 50px);
    }
</style>
<body>

    <div class="box">
        <div class="box2"></div>

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

image.png
上一篇 下一篇

猜你喜欢

热点阅读