Using CSS border is the standard way to outline an element. But it has a side effect that breaks layouts: borders add to the element's total width and height.
If you have a 100px wide div and add a 5px border, it suddenly becomes 110px wide. In a tight grid or flexbox layout, this causes elements to overflow or wrap unexpectedly.
You can fix this globally by setting box-sizing: border-box , but sometimes you need a border that doesn't take up any space at all, or you want multiple borders on a single element.
The solution is to use box-shadow .
The Problem with Borders
Here is a standard box:
.box { width : 100px ; height : 100px ; border : 2px solid blue ; }
Enter fullscreen mode
Exit fullscreen mode
Total width: 104px.…