首页 > css margin-left的百分比为什么只是相对于父元素内容的宽度?

css margin-left的百分比为什么只是相对于父元素内容的宽度?

对绝对定位元素做水平居中时,伪元素before的margin-left的百分比只是相对于.center内容的宽度,不包含padding的大小;
设置了box-sizing也是无效.

.center {
    left: 50%;
    right: auto;
    position: absolute;
    padding: .425em .25em;
    box-sizing: border-box;
}
.center:before{   
    content: '';
    display: inline-block;
    width: .1px;
    margin-left: -50%;
}

我的答案可能文不对题。
对绝对元素的居中 可参照这个答案:http://.com/q/1010000004248252/a-1020000004248303

【热门文章】
【热门文章】