Add a transparent border to .itemand change the color on hover.
.item {
border: 8px solid transparent;
background-clip: content-box;
}
.item:hover {
border-color: green;
}
Also note the use of the property background-clip. This will limit the background color to the content area only, with the exception of borders.
.item {
height: 250px;
width: 250px;
display: block;
background: orange;
border: 8px solid transparent;
background-clip: content-box;
-webkit-transition: all .5s ease-in-out;
transition: all .5s ease-in-out;
}
.item:hover {
border-color: green;
}
<div class="item"></div>
Run codeHide result source
share