码迷,mamicode.com
首页 > 其他好文 > 详细

绝对定位元素的百分比margin

时间:2016-09-06 12:11:34      阅读:124      评论:0      收藏:0      [点我收藏+]

标签:

绝对定位元素的百分比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>

 

绝对定位元素的百分比margin

标签:

原文地址:http://www.cnblogs.com/yatao/p/5844953.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!