Result
CSSで任意の箇所にスポットライトを当てる、というもの
やってる事は一番下のレイヤーに画像、2つ目のレイヤーに透過オーバーレイ、
3つ目のレイヤーに1つ目の画像と同じ画像を用意し、円状にくり抜いて重ねる、という感じです
css
.img-wrapper {/*親*/
display: grid;
max-width: 600px;
margin: 20px;
box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.8);
}
.img {/*1つ目のレイヤー*/
width: 100%;
grid-area: 1 / 1;
}
.img--highlight {/*3つ目でくり抜き*/
clip-path: circle(100px at 55% 65%);
}
.img-layer {/*2つ目のレイヤーの透過オーバーレイ*/
background: rgba(0, 0, 0, 0.7);
grid-area: 1 / 1;
}
レイヤーはpositionではなく、display: grid;をgrid-area: 1 / 1;と設定して重ねています
html
<div class="img-wrapper"> <img class="img" src="https://picsum.photos/1200/1000?image=5" alt=""> <div class="img-layer"></div> <img class="img img--highlight" src="https://picsum.photos/1200/1000?image=5" alt=""> </div>
can i use
clip-pathのブラウザ対応状況です。
