绝对定位元素的百分比margin

绝对定位元素的百分比margin是相对于第一个定位元素祖先元素(relative/absolute/fixed)的宽度(width)计算的
橙色的宽度(width)为1000px,
蓝色的宽度(width)为600px,
img的margin为10%,
margin-left等于1000*10%,
margin-top等于1000*10%。
这时图片的margin值只与第一个定位元素的宽度有关.
<!DOCTYPE html>
<html>
      <head>
            <meta charset="UTF-8">
            <title></title>
            <style type="text/css">
            #bigbox{
                  width: 1000px;
                  height: 200px;
                  background: lightcoral;
                  position: absolute;
            }
            #box{
                  width: 600px;
                  height: 200px;
                  background: deepskyblue;

            }
            img{
            margin:10%;
            position: absolute;
            }
            </style>
      </head>
      <body>
            <div id="bigbox">
                              <div id="box">
                  <img src="img/logo.jpg"/>
            </div>
            </div>

      </body>
</html>

 

posted @ 2016-09-06 11:05  桃园  阅读(1485)  评论(0编辑  收藏  举报