0

any ideas how to do it with the help of css? The second one(blue border) is the image with :hover.

I thought about one image over another, and the last one with border.

enter image description here

SERG
  • 3,907
  • 8
  • 44
  • 89

2 Answers2

1

Borders are always on the outside of elements...there is no "inset border" option.

An alternative is an inset box-shadow.

div {
    display: inline-block;
    width: 200px;
    height: 200px;
    background-image: url(http://lorempixel.com/output/food-q-c-200-200-3.jpg);
    border-radius:16px;
    box-shadow: inset 0 0 0 15px rgba(255,255,255,0.5);
    transition:box-shadow 0.5s ease;
}

div:hover {
    box-shadow: inset 0 0 0 15px rgba(0,0,155,1);
}
<div>
</div>

EDIT:

Inside radius option requires another element. I have used a pseudo-element in this instance.

* {
    -webkit-box-sizing: border-box;
    -moz-box-sizing: border-box;
    box-sizing: border-box;
}

div {
    display: inline-block;
    width: 200px;
    height: 200px;
    background-image: url(http://lorempixel.com/output/food-q-c-200-200-3.jpg);
    border-radius:16px;
    position: relative;
    overflow: hidden;
}

div::after {
    content: '';
    position: absolute;
    border-radius:16px;
    top:12px;
    left: 12px;
    height: calc(100% - 25px);
    width: calc(100% - 25px);
    z-index: 1;
    background: transparent;
    box-shadow: 0 0 0 32px rgba(255,255,255,0.8);
}

div:hover:after {
    box-shadow: 0 0 0 24px rgba(0,0,155,1);
}
<div></div>
Paulie_D
  • 107,962
  • 13
  • 142
  • 161
0

Set the border with default color. Then img:hover{---}

<div>
<img src="http://dummy-images.com/abstract/dummy-480x270-Bottles.jpg">
</div>

CSS

img{border:10px solid rgba(0,0,0,0.8);border-radius:8px;}
img:hover{border:10px solid blue;}

Check the Demo

CodeRomeos
  • 2,428
  • 1
  • 10
  • 20