18910140161

为什么padding:0时,border 与 content 之间存在缝隙?

顺晟科技

2021-07-09 11:25:01

194

最开始不加边框时,内部元素跟父容器还严丝合缝,但是一旦加了 border 以后,border 和 content 之间就出现了一条小缝隙,不知是什么原因,css 如下:

没加边框:

.bar-content {
    width: ;
    height: 40px;
    background-color: black;

    display: flex;
    flex-direction: row;
    justify-content: space-between;
}
.navigation-btn {
    flex: 1;
    height: 40px;

    line-height: 40px;
    text-align: center;

    color: whitesmoke;

    transition:background-color .2s
}

image.png加边框:

.bar-content {
    border: 2px solid green;
    width: ;
    height: 40px;
    background-color: black;

    display: flex;
    flex-direction: row;
    justify-content: space-between;
}
.navigation-btn {
    flex: 1;
    height: 40px;

    line-height: 40px;
    text-align: center;

    color: whitesmoke;

    transition:background-color .2s
}

image.png虽然看不清楚,但是边框和内容之间有一条黑线。盒模型:image.png

可能是 HTML 绘制的时候有点色偏。

如果把 border 改大一点,比如 5;或者放大显示在 200%;应该就看不见那么黑边了(但不是,有时候刷刷还会出来,刷刷又没了)。

会不会因为width: 和border导致内容溢出,撑开有个水平滚动条?加box-sizing: border-box;看看

相关文章
我们已经准备好了,你呢?
2024我们与您携手共赢,为您的企业形象保驾护航