1

I have a border around my .tab-content and the same border around active .tabs. I've tried adding a transparent border on the bottom to no avail.

my-setup

Is there a way to, where two borders overlap, have one override the other? Or is there a better way to accomplish this?

Here's a jsfiddle to show my basic set up.

.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>

0

1 Answer 1

2

You can use a pseudo element to create the bottom border, make it the same color as the background, and position it to cover the dark line.

.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>

Or just move the whole navbar 1px down.

.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>

Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Pangloss! This works pretty well but it still leaves a tiny sliver of a line in Chrome and extending the bottom to -2px to completely cover it makes the left and right borders stick out down below the line (Works perfectly in Firefox).
I dunno, might be my OS or screen or something. It changes in noticeability when zooming in and out, but you can see it here - i.imgur.com/P9n2XMh.png But it's not that big of a deal. Thanks for the help!
It gonna be hard to debug, as I can't see that extra line here. Try the first pseudo element approach, and set to bottom:-2px; or so.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.