zoukankan      html  css  js  c++  java
  • css绝对定位的盒子居中算法

    绝对定位的盒子居中

    加了绝对定位的盒子不能通过margin:0 auto水平居中,但是可以通过以下方法实现水平居中。

    ①left:50%;让盒子的左侧移动到父级元素的水平中心位置
    ②margin-left:-100px;让盒子向左移动自身宽度的一半。

    <!DOCTYPE html>
    <html lang="en">
    <head>
    	<meta charset="UTF-8">
    	<title></title>
      <style type="text/css">
        .box {
          position: absolute;
          left: 50%;
          margin-left: -100px;
           200px;
          height: 200px;    
          background-color: pink;
        }
      </style>
    </head>
    <body>
      <div class="box"></div>
    </body>
    </html>
    
  • 相关阅读:
    地铁开发进度1
    人月神话阅读笔记二
    学习进度五
    人月神话阅读笔记一
    WebView的用法:
    图框联动
    阅读笔记《人月神话》一
    5
    4
    3
  • 原文地址:https://www.cnblogs.com/qjuly/p/13448593.html
Copyright © 2011-2022 走看看