box-sizing: border-box;妙用

66 阅读1分钟

image.png

image.png

图一变图二,只改一句代码

    <view class="box">
        <view class="box_content">
            <text>首页</text>
            <text>首页</text>
            <text>首页</text>
            <text>首页</text>
            <text>首页</text>
        </view>
    </view>
    
   .box {
    1.  width: 100%;
    1.  padding: 20px;
    1.  position: fixed;
    1.  top: 0;
    1.  left: 0;  
    }
    .box_content{
        1.  display: flex;
        1.  justify-content: space-between;
    }

●content-box:浏览器对盒模型的解释遵从W3C标准,当定义width和height时,它的参数值不包括border和padding。

●border-box:当定义width和height时,border和padding的参数值被包含在width和height之内。

view, text {
    box-sizing: border-box;
}