How to create a responsive skew background

Asked

Viewed 23 times

-1

I did a background Skew using pseudo-Elents but the red part is outside the margin of the page, as help to stay only inside the margin ?

        *{
            margin: 0;
            padding: 0;
        }
.content{
    background-color: chartreuse;
    width: 100%;
    height: 100vh;
}
.content::before{
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 30%;
    background-color: cornflowerblue;
    transform: skew(-10deg);
    transform-origin: top;
}
.content::after{
    content: '';
    position: absolute;
    right: -60px;
    top: 0;
    bottom: 0;
    width: 30%;
    background-color: #ff0000;
    transform-origin: top;
}
    <div class="content">
        <h1>NADA</h1>
    </div>

1 answer

1


Face the problem is the right: -60px that you put in the pseudo element

To correct this one of the options is to discount 60px of width and not play the element 60px out of the screen with a right negative

For that use a calc, like your width is 30% Take 60px out of it, like this:

width: calc(30% - 60px);

See the result in the example below

      *{
            margin: 0;
            padding: 0;
        }
.content{
    background-color: chartreuse;
    width: 100%;
    height: 100vh;
}
.content::before{
    content: '';
    position: absolute;
    right: 0;
    top: 0;
    bottom: 0;
    width: 30%;
    background-color: cornflowerblue;
    transform: skew(-10deg);
    transform-origin: top;
}
.content::after{
    content: '';
    position: absolute;
    right: 0px;
    top: 0;
    bottom: 0;
    width: calc(30% - 60px);
    background-color: #ff0000;
    transform-origin: top;
   
}
<div class="content">
    <h1>NADA</h1>
</div>

  • Vlw got it, a doubt think it’s worth using images made in photoshop to create these backgrounds? or css is the best?

  • @Javascripto in this particular case for sure CSS, I have no doubt about it... even if you want an image inside just put as background image etc, there is no pq to do anything in Photoshop in this case. Young person if you think the answer solved the problem remember to mark it as accepted in this icon , below the arrows next to the answer, so it is not open even if it has been solved ;)

  • obg marquei, solved yes, to starting and was considering the possibility of using images to get my backgrounds skew, curves, slantled.. , obg good afternoon.

  • @Javascripto was worth the man force

Browser other questions tagged

You are not signed in. Login or sign up in order to post.