There are two more options that can and should be met with box-shadow
and another with calc()
deducting from height
and width
edge thickness.
Option 1: Using box-shadow
with inset
and spread-radius
inclusive with this technique you can make multiple borders in and out of the element without affecting anything that is around!
/ p>
OBS: spread-radius
is the fourth property parameter, it is optional and you may not always use it. I put between "4px" just to visualize you better.
/* offset-x | offset-y | blur-radius | spread-radius | color */
box-shadow: 2px 2px 2px " 4px " rgba(0, 0, 0, 0.2);
See the example below, I used as a basis the model of our friend @Bacco who is well didactic.
html, body {
width: 100%;
height: 100%;
margin: 20px;
padding: 0;
}
div {
display:inline-block; vertical-align:middle;
width:120px;height:60px; background-color:#fcc;
text-align:center;
}
#a { box-shadow: 0 0 4px black inset; }
#b, #c { box-shadow: 0 0 0 4px black;}
#c { box-shadow: 0 0 0 4px black inset; }
#e { box-shadow: 0 0 4px black inset, 0 0 0 4px black, 0 0 0 6px red, 0 0 0 8px lime, 0 0 0 10px purple;}
<div id="a">box-shadow inset sem "spread-radius"</div>
<div id="b">com box-shadow</div>
<div id="c">box-shadow inset com "spread-radius"</div>
<div id="d">sem box-shadow</div>
<div id="e">várias box-shadow e 1 inset</div>
Here you can read more about the box-shadow
property: link
Option 2: In this technique you will centralize the contents of the DIVs with Flex-Box
and then put the Embroidery in :hover
but discounting the width width of the height and width of Div
Ex: If you have a border of 4px you will have to shoot 8px of the height and width of the DIV, 8px as they are 4px on each side, so we have 8px
div:hover {
border: 4px solid black;
width:calc(120px - 8px);
height:calc(60px - 8px);
}
See in the example below the applied technique
html, body {
width: 100%;
height: 100%;
margin: 20px;
padding: 0;
}
div {
background-color:#fcc;
display: flex;
justify-content: center;
align-items: center;
flex-direction: row;
margin: 2px;
width:120px;
height:60px;
}
div:hover {
cursor: pointer;
border: 4px solid black;
}
div.calc:hover {
cursor: pointer;
border: 4px solid black;
width:calc(120px - 8px);
height:calc(60px - 8px);
}
<section style="display: flex;flex-direction: row;">
<div class="calc">COM calc()</div>
<div class="calc">COM calc()</div>
<div>SEM calc()</div>
<div>SEM calc()</div>
</section>