开发者社区 问答 正文

为什么子元素设置{position:relative;left:-50%; }这里的50%是父元素宽度的50%

如题。
不理解为什么父元素设置了
wrap{float:left;position:relative;left:50%}
子元素设置了
innerWrap{position:relative;left:-50%}
子元素是向左偏移了是父元素宽度的50%。

展开
收起
a123456678 2016-05-27 17:09:24 2710 分享 版权
1 条回答
写回答
取消 提交回答
  • .parent {
        position: relative;
        width: xxpx;
        height: xxpx;
    }
    .child {
        position: absolute;
        left: 50%;
        top: 50%
        transform: translate(-50%, -50%);
        width: yypx;
        height: yypx;
    }
    2019-07-17 19:18:21
    赞同 展开评论
问答地址: