An effective approach is to create a border effect without applying an actual border directly to the element. By utilizing the :before
and :after
pseudo-elements as transparent boxes positioned on the left and right sides, we can achieve the desired outcome. These pseudo-elements have transparent backgrounds and borders that do not interfere with the content, producing the desired visual effect.
This technique is compatible with various backgrounds: http://jsfiddle.net/kkYrP/8/
.box{
position:relative;
}
.box:before{
content: "";
position: absolute;
top: -2px;
left: -2px;
bottom: -2px;
width: 8%;
border: 2px solid #333;
border-right:none;
z-index:1;
}
.box:after{
content: "";
position: absolute;
top: -2px;
right: -2px;
bottom:-2px;
width: 8%;
border: 2px solid #333;
border-left:none;
z-index:1;
}
Tip: To address any clicking or hovering issues, consider adding pointer-events:none;
to both the :before
and :after
pseudo-elements.