JSFiddle - React, Tailwind, and code Playground
HTML
<div class="box">
<div class="text"></div>
<div class="rect-shadow"></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;
}
.rect-shadow {
position: absolute;
left: var(--x);
top: var(--y);
width: var(--w);
height: var(--h);
border-radius: var(--r);
box-shadow: 0 0 0 3000px rgba(0, 0, 0, 0.5);
}
JavaScript
const textElem = document.querySelectorAll('.text')
textElem.forEach(item => {
item.textContent = '测试文字'.repeat(176)
})