I’ve a parent container PROMO, with fixed width and I need to stretch background color (#f9f9f9) to full page (wider than parent’s width). Example you can see on the screenshot.
(https://phpout.com/wp-content/uploads/2023/08/YSxpv-jpg.webp)
<section class="promo">
<div class="promo__wrapper">
<h1 class="promo__wrapper-title">Милые штуки ручной работы для дома</h1>
</div>
<div class="promo__add">
<a class="promo__choice" href="#"><span class="promo__choice-description">Предметы интерьера</span>
<svg class="promo__choice-lamp" width="40" height="62">
<use xlink:href="./img/sprite.svg#lamp-icon"></use>
</svg>
</a>
<a class="promo__choice" href="#"><span class="promo__choice-description">Детские игрушки</span>
<svg class="promo__choice-cube" width="60" height="60">
<use xlink:href="./img/sprite.svg#toy-icon"></use>
</svg>
</a>
</div>
<picture>
<source media="(min-width: 1150px)" width="1150" height="34" srcset="./img/icons/wave-desktop.svg">
<source media="(min-width: 768px)" width="768" height="24" srcset="./img/icons/wave-tablet.svg">
<img class="promo__wave">
</picture>
</section>
I tried to use background child container, but in this case, there is a horizontal scroll on the page.
(https://phpout.com/wp-content/uploads/2023/08/bwSbR.png)
.promo::before {
position: absolute;
content: "";
height: 680px;
width: 100vw;
margin-left: calc(-50vw + 50%);
background-color: #f9f9f9;
top: 0;
left: 0;
}
4
Answers
Creo que el problema lo tienes en el margin-left. Yo probaría a quitarlo y además resetearía los márgenes que tuviera por defecto el navegador con la siguiente línea de código:
Instead of doing it using before selector just make it simple,
Give
background-color: your-bg-color
to the classpromo
and wrap inner content of classpromo
in another div and add horizontal padding as you need.Css will look like
The horizontal scrollbar appears because of the vertical scrollbar. It’s width is added to the
100vw
resulting the horizontal overflow. If you remove the scrollbar width from the pseudo-element then the horizontal scrollbar will go away.