盒子绝对定位 position:foxed ; 居中

时间:2017-12-02 10:28:22   收藏:0   阅读:270

方法1

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <style>
        body{
            width:  100%;
            height: 1600px;
            background-color: #c9c7c7;

        }
        p{
            max-width: 500px;
            width: 100%;
            background: red;
            position: fixed;color: white;
            text-align: center;
            left: 0;
            right: 0;
            margin: auto;
        }
    </style>
</head>
<body>

<p>我是绝对定位 我需要居中</p>

</body>
</html>

方法2  (替换上面style 的p标签的样式      )

p{
            max-width: 500px;
            width: 100%;
            background: red;
            position: fixed;color: white;
            text-align: center;
            left:50%;
            transform: translateX(-50%);

        }

 

原文:http://www.cnblogs.com/aqigogogo/p/7953418.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!