In this example, the image is superimposed on the container block via :: before with negative left: -80px. And here you are good, i.e. no scrolling up to width: 300px.
But, if you do instead of left: -80px; -> right: -80px; so that the overlay is calculated relative to the right corner of the container. And horizontal scrolling appears already at width less than 492px;
How to remove scrolling for the right option? (i.e. do as in the left one). Without (overflow: hidden)
* {
margin: 0;
padding: 0;
}
div {
margin: 100px auto;
border: 1px solid gray;
width: 500px;
position: relative;
}
.bg-img::before {
content: "";
position: absolute;
width: 160px;
height: 110px;
z-index: -1;
top: -50px;
left: -80px; /* is ok */
/* right: -80 */ /* bad */
background-image: url(https://i.ibb.co/Qdz79gF/Sample.png);
background-size: 100% 100%;
}
<div class="bg-img">
This is some text<br>
This is some text<br>
This is some text<br>
This is some text<br>
This is some text
</div>