I am trying to add border which is inside the box, I need to use css after or before for this, how can I achieve this effect?
.box {
width: 100px;
height: 100px;
background: red;
}
<div class="box"></div>
I am trying to add border which is inside the box, I need to use css after or before for this, how can I achieve this effect?
.box {
width: 100px;
height: 100px;
background: red;
}
<div class="box"></div>
There's a lot of different ways you can achieve this effect, each with their own pros and cons (including how different properties affect document flow):
.box {
width: 100px;
height: 100px;
background-color: red;
outline: 2px solid darkred;
outline-offset: -7px;
}
<div class="box"></div>
.box {
width: 100px;
height: 100px;
border: 2px solid darkred;
background-color: red;
box-shadow: 0 0 0 5px red;
}
<div class="box"></div>
.box {
position: relative;
width: 100px;
height: 100px;
background-color: red;
}
.box::after {
content: '';
position: absolute;
top: 5px;
right: 5px;
bottom: 5px;
left: 5px;
border: 2px solid darkred;
}
<div class="box"></div>