实现任意元素的居中

2019-06-25  本文已影响0人  小透明进击战
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
    <style>
        .out {
            width: 400px;
            height: 400px;
            background-color: firebrick;
            margin: 200px auto;
            position: relative;
        }
        .inner {
            width: 60px;
            height: 60px;
            background-color: goldenrod;
            position: absolute;
            left: 50%;
            top: 50%;
            /*translate中百分比是以自己本身元素的宽高为参考*/
            transform: translate(-50%,-50%);
        }
    </style>
</head>
<body>
<div class="out">
    <div class="inner"></div>
</div>
</body>
</html>
上一篇 下一篇

猜你喜欢

热点阅读