position:fixed(相对于视窗来定位、一个固定定位元素不会保留它原本在页面应有的空隙(脱离文档流))

975 阅读1分钟

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>11.fixed</title>
    <style>
        *{
            margin: 0;
            padding: 0;
        }
        .fixed{
            position: fixed;
            width: 300px;
            height: 300px;
            left: 0;
            top: 0;
            background: greenyellow;
            display: flex;
            justify-content: center;
            align-items: center;
            font-weight: bold;
            font-size: 50px;
        }
    </style>
</head>
<body>
<div class="fixed">
    把我固定
</div>
</body>
</html>