Tab header 为重叠边框制作透明边框

Tab header make transparent border for overlapping border

我的 .tab-content 周围有边框,活动 .tab 周围也有相同的边框。我试过在底部添加透明边框无济于事。

有没有办法在两个边界重叠的地方让一个覆盖另一个?或者有更好的方法来完成这个吗?

这里 jsfiddle 展示了我的基本设置。

.tab-content {
    height:200px;
    width:400px;
    background-color: #aaa;
    border:1px solid #000;
}

.tabs-container {
    height:auto;
    width:400px;
    background-color:#aaabbb;

}

.tabs {
    width:360px;
    margin-left:20px;
}

.tab {
    display:inline-block;
    padding:5px 20px;
}

.tab.active {
    border-left:1px solid #000;
    border-right:1px solid #000;
    border-top:1px solid #000;
    border-bottom:transparent;
    background-color: #aaa;
}
<div class="tabs-container">
    <div class="tabs">
        <div class="tab active">This Tab</div>
        <div class="tab">That Tab</div>
    </div>
</div>

<div class="tab-content">
</div>

可以使用伪元素创建下边框,使其与背景颜色相同,并定位到遮住暗线。

.tab.active:after {
    content: '';
    border-bottom: 10px solid #aaa;
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
}

.tab-content {
    height:200px;
    width:400px;
    background-color: #aaa;
    border:1px solid #000;
}

.tabs-container {
    height:auto;
    width:400px;
    background-color:#aaabbb;

}

.tabs {
    width:360px;
    margin-left:20px;
}

.tab {
    display:inline-block;
    padding:5px 20px;
}

.tab.active {
    border-left:1px solid #000;
    border-right:1px solid #000;
    border-top:1px solid #000;
    background-color: #aaa;
    position: relative;
}
.tab.active:after {
    content: '';
    border-bottom:10px solid #aaa;
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
}
<div class="tabs-container">
    <div class="tabs">
        <div class="tab active">This Tab</div>
        <div class="tab">That Tab</div>
    </div>
</div>

<div class="tab-content">
</div>

或者将整个导航栏向下移动 1px。

.tab.active {
    border-left:1px solid #000;
    border-right:1px solid #000;
    border-top:1px solid #000;
    background-color: #aaa;
    position: relative;
    bottom: -1px;
}

.tab-content {
    height:200px;
    width:400px;
    background-color: #aaa;
    border:1px solid #000;
}

.tabs-container {
    height:auto;
    width:400px;
    background-color:#aaabbb;

}

.tabs {
    width:360px;
    margin-left:20px;
}

.tab {
    display:inline-block;
    padding:5px 20px;
}

.tab.active {
    border-left:1px solid #000;
    border-right:1px solid #000;
    border-top:1px solid #000;
    background-color: #aaa;
    position: relative;
    bottom: -1px;
}
/* .tab.active:after {
    content: '';
    border-bottom:10px solid #aaa;
    position: absolute;
    bottom: -1px;
    left: 0;
    width: 100%;
} */
<div class="tabs-container">
    <div class="tabs">
        <div class="tab active">This Tab</div>
        <div class="tab">That Tab</div>
    </div>
</div>

<div class="tab-content">
</div>