JSFiddle - React, Tailwind, and code Playground
HTML
<div class="box">
<div class="text"></div>
<div class="overlay">
<div class="spoltlight">
</div>
</div>
</div>
CSS
:root {
--x: 150px;
--y: 100px;
--w: 300px;
--h: 200px;
--r: 10px;
}
.box {
position: relative;
width: 600px;
height: 400px;
margin-bottom: 10px;
overflow: hidden;
background: #fff;
}
.overlay {
position: absolute;
top: 0; right: 0; bottom: 0; left: 0;
z-index: 99999;
background-color: rgba(0, 0, 0, 0.5);
mix-blend-mode: hard-light;
pointer-events: auto;
}
.spoltlight {
position: absolute;
left: var(--x);
top: var(--y);
width: var(--w);
height: var(--h);
border-radius: var(--r);
background-color: gray;
}
.spoltlight::after {
content: "";
position: absolute;
top: 100%;
right: 50px;
border: 15px solid transparent;
border-top-color: gray;
}
JavaScript
const textElem = document.querySelectorAll('.text')
textElem.forEach(item => {
item.textContent = '测试文字'.repeat(176)
})