I made the following codepen: https://codepen.io/chiptus/pen/rZKJyy where I have a spotlight with a wide source that can move around. it sort of works but for some reason there is a whitespace between the triangles and the center rectangle.
The spotlight container is just there so the spotlight won't interact with the flow of the page.
The spotlight is constructed from three parts - two triangles and a center rectangle. The two triangles are created used games with the border and the rectangle is just a div block with the same color as the triangles.
This is the CSS (there are some variables I removed):
.spotlight-container > div {
display: inline-block;
}
.spotlight-center {
position: relative;
height: 100%;
text-align: center;
}
.spotlight-left::before,
.spotlight-right::before,
.spotlight-left::after,
.spotlight-right::after {
content: '';
}
.spotlight-center {
display: inline-block;
margin-top: var(--spotlight-sourcey);
height: calc(var(--spotlight-height) - var(--spotlight-sourcey));
width: calc(var(--spotlight-source-width) * var(--spotlight-width));
background-color: var(--spotlight-color);
}
.spotlight-left::before {
display: inline-block;
margin-top: var(--spotlight-sourcey);
height: 0;
width: 0;
border: 3px solid;
border-top-width: 0;
border-bottom-width: calc(var(--spotlight-height) - var(--spotlight-sourcey));
border-left-width: calc(var(--spotlight-sourcex) * var(--spotlight-width));
border-right-width: 0;
border-color: transparent transparent var(--spotlight-color);
}
.spotlight-right::before {
display: inline-block;
margin-top: var(--spotlight-sourcey);
height: 0;
width: 0;
border: 3px solid;
border-top-width: 0;
border-bottom-width: calc(var(--spotlight-height) - var(--spotlight-sourcey));
border-left-width: 0;
border-right-width: calc(
(1 - var(--spotlight-sourcex)) * var(--spotlight-width)
);
border-color: transparent transparent var(--spotlight-color);
}