开发者社区 问答 正文

absolute div同时设置left和right,在margin:0 auto的情况下偏移的问题

<!DOCTYPE html>
<html>
 <head>
  <meta http-equiv="Content-Type" CONTENT="text/html; charset=UTF-8"/>
  <title>菜单</title>
<style type="text/css">
  *{
    margin: 0;
    padding: 0;
  }
  div{
   margin:0 auto;
   text-align:center;
  }
  .father{
    width: 200px;
    height: 200px;
    background-color: #ffff00;
    border: 1px solid #000;
    position: relative;
  }

  .son{
    width: 100px;
    height: 100px;
    background-color: #0000ff;
    border: 1px solid #ff0000;
    position: absolute;
    top: 20px;
    left: 20px;
    right:-70px;
  }
  </style>

 </head>
 <body>


<div>
    <div class="father">
      <div class="son">
      </div>
    </div>
  </div>


 </body>
</html>

screenshot

展开
收起
a123456678 2016-03-25 16:45:17 2473 分享 版权
0 条回答
写回答
取消 提交回答
问答地址: