My menu has 2 borders: the main vertical border on the right of the whole menu and the border (top, bottom, left) of the active item. The right border of the active item should be empty. The main border should be interrupted in the same place where the active item right border was interrupted. Note that any of the items could be active, that is why the main border interruption can’t be hardcoded
.container {
border-right: 1px solid;
width: 200px;
padding-top: 20px;
padding-bottom: 20px;
}
.item {
padding: 10px;
}
.active {
border-top: 1px solid;
border-bottom: 1px solid;
border-left: 1px solid;
}
<div class="container">
<div class="item active">
Test1
</div>
<div class="item">
Test2
</div>
<div class="item">
Test3
</div>
</div>
5
Answers
To get the expected output rewrite the above styles :
You can’t "interrupt" a border of a container for a specific child.
The only option is to "hide" that section of the border with a colored border on the child over that border section.
I’d suggest a positioned pseudo-element with the same background at the background of the container.
To achieve this behavior, set the active element’s background to an opaque color and set the
width
of active element to:With
containerWidth
being width of the parent container element andpadding
the padding size of active element. In this case its180px
:You can add a
box-shadow
for the right part to hide the border.You can add the
margin-right: -1px;
andbackground: white;
into the.active
class CSS.