当div为position: fixed自适应居中

<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>当div为position: fixed自适应居中</title>
        <style>
            .fixed {
                width: 300px;
                height: 150px;
                background-color: red;
                position: fixed;
                top: 20%;
                left: 0;
                right: 0;
                margin: 0 auto;
            }
        </style>
    </head>
    <body>
        <div class="foxed">
            fixed浮动居中
        </div>
    </body>
</html>html

相关文章
相关标签/搜索