I have been experimenting with CSS pseudo-classes, specifically the before
and after
classes. While I have had no issues with the before
class, I am running into a horizontal scroll problem when using the after
class.
I want to avoid using overflow: hidden;
as it causes my image to display behind the first section.
Can someone assist me in resolving these problems?
The before
class is functioning correctly:
.container {
width: 1140px;
margin: auto;
}
/*.test1{position: relative;}*/
.test1:before {
content: "";
background-image: url('https://w0.pngwave.com/png/546/532/computer-icons-sales-label-sale-icon-png-clip-art.png');
background-repeat: no-repeat;
background-size: contain;
width: 350px;
height: 308px;
display: block;
position: absolute;
top: -15%;
left: -10%;
}
<div class="container">
<section class="test1">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</section>
</div>
The after
class is causing a scrollbar issue:
section {
height: 400px;
position: relative;
}
.test1 {
overflow: hidden;
}
.test1:after {
content: "";
background-image: url('https://www.netclipart.com/pp/m/16-165891_sale-price-tag-png-sale-icon-png.png');
background-repeat: no-repeat;
background-size: contain;
width: 350px;
height: 308px;
display: block;
position: absolute;
top: -15%;
right: -10%;
}
<section style="background-color: #f8f8f8;">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
</section>
<section class="test1">
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure
dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
</section>
https://i.sstatic.net/mlZw7.png My desired output