There are two more options that can and suit one with box-shadow
and another with calc()
discounting from height
and width
the thickness of the edge.
Option 1: Using box-shadow
with inset
and spread-radius
including with this technique it is possible to make several edges inside and out of the element without affecting anything that is around!
OBS: spread-radius
is the fourth parameter of the property, it is optional and you can not use it always. I put in between " 4px " just for you to see 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 the model of our friend @Bacco that 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 property box-shadow
: https://developer.mozilla.org/en-US/docs/Web/CSS/box-shadow
Option 2: In this technique you will centralize the content of Divs with Flex-Box
and then place the embroidery on the :hover
but excluding the width of the border from the height and width of the Div
Ex: If vc has a 4px edge vc will have to drop 8px from the height and width of the DIV, 8px because it is 4px on each side, so we have 8px
div:hover {
border: 4px solid black;
width:calc(120px - 8px);
height:calc(60px - 8px);
}
See Example below for 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>
You can just apply a transparent border and when the mouse goes over apply the desired color.
– Danilo Assis