margin-top=10%,这10%居然是相对于父元素的宽度,宽度?

是的你没有看错,是父元素的width,不是height

明明记得之前学的是可以用margin-top:50%,transform:translateY(-50%)来实现垂直居中的啊,怎么今天用了一下margin-top=5%高度竟然有点不对劲???搜索了一下发现padding和margin无论left还是right还是top还是bottom都是相对于父元素的width的,上验证代码:

<template>
   <div class="father">
      <div class="sonOne"></div>
      <div class="sonTwo"></div>
   </div>
</template>

<script>
export default {

}
</script>

<style  scoped>
.father{
    width: 500px;
    height: 300px;
    background: rgb(171, 202, 228);
}
.sonOne{
     width: 500px;
    height: 50px;
    background: rgb(95, 109, 189);
}
.sonTwo{
     width: 500px;
    height: 100px;
     margin-top: 10%;
    background: rgb(43, 66, 197);
}
</style>

 sonTwo的margin-top: 10%,F12后发现margin-top=50px,是父盒子width(500px)的10%

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值