反常识,margin-top的百分比竟然是相对于父元素的宽度!

<下方内容引用自网络>【因遇到此问题,故将其抄录在此】

css margin 的值是百分百的时候,其值是基于父元素的宽度来计算的,并非是自身的宽度,padding 百分比的取值也是一样的,
css height 的高度百分比是按其父元素的高度来计算的

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style type="text/css">
        .box{ background: #ccc;border: 1px solid #ccc; width: 900px; height: 300px; }
        .pox{ background: #f0f; width:50%; height: 50%; margin-top: 50%; }
    </style>
</head>
<body>
    <div class="box"> 
      <div class="pox"></div>

    </div>
</body>
</html>
<script type="text/javascript" src='zepto.js'></script>
<script type="text/javascript">
    $(function(){
    console.log($('.pox').css('margin-top'))
    console.log($('.pox').width())
    })
</script>


  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值