先来看效果
<body>
<div class="box">
<div class="div1">
<div class="content"></div>
</div>
<div class="div2">
<div class="content"></div>
</div>
</div>
</body>
<style>
.box{
display: flex;
justify-content: center;
margin-top: 40px;
}
.div1,
.div2 {
width: 100px;
height: 100px;
background-color: yellow;
box-sizing: border-box;
}
.div2 {
border: 2px solid red;
margin-left: 50px;
}
.content {
width: 100%;
height: 100%;
background-color: sandybrown;
}
</style>
现象
div1与div2大小一致,div2仅比div1多了边框里面的content宽高也占父级的100%,但是在页面不同缩放比例的情况下,出现了空白缝隙。
造成该现象的原因
因为浏览器在缩放时,其真实像素和设备相关连,就相当于是理论像素和物理像素不一的可能性
解决办法
在.content
盒子(也就是子盒子)添加如下代码:
border: 2px solid red; //当然1px也是可以的,那对应的margin就是-1px,此案例用的2px
margin: -2px;