Like leaving a pie div?

Asked

Viewed 501 times

1

Hello, recently I found a layout on Google and I found the idea of it very interesting, but I do not know how to reproduce the div that way, is basically to make the div 'pie', I tried to reproduce but when I used the Rotate(), the div sprained but was not glued to both sides, even with width: 100%; so I will post the layout here and would appreciate if someone showed me how to accomplish the same thing in one of those Divs. inserir a descrição da imagem aqui

3 answers

2

I made a simple example using skew only in the elements ::after and ::before. So I do an X with the elements, and the main content does not even need to use skew to fix. Watch out for the use of z-index also because a ::after is above the image and the ::before underneath

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
.s {
    width: 100%;
    height: 400px;
    background-image: url(http://unsplash.it/800/500);
    background-size: cover;
    background-position: center top;
    position: relative;
    z-index: -3;
}

.c {
    width: 100%;
    height: 200px;
    display: flex;
    justify-content: center;
    align-items: center;
    position: relative;
    top: -13%;
}
.box {
    width: 100px;
    height: 100px;
    background-color: #fff;
    margin: 20px;
}
.c::before {
    content: "";
    width: 100%;
    height: 200px;
    background-image: url(http://unsplash.it/800/500);
    background-size: cover;
    background-position: center bottom;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -4;
    transform: skewY(3deg);
}
.c::after {
    content: "";
    width: 100%;
    height: 200px;
    background-color: aqua;
    position: absolute;
    top: 0;
    left: 0;
    z-index: -1;
    transform: skewY(-4deg);
}
<div class="s">
    Lorem ipsum dolor sit amet consectetur, adipisicing elit. Velit, nihil!
</div>
<div class="c">
    <div class="box">
        oi
    </div>
    <div class="box">
        oi
    </div>
    <div class="box">
        oi
    </div>
</div>


Example using the two techniques, reversing values of skew between father and son, and another technique using skew only in the ::after

Here on the Stackoverflow Snippet it won’t work well, but then you can test it on your project.

html, body {
    width: 100%;
    height: 100%;
    margin: 0;
    padding: 0;
}
.s {
    width: 100%;
    height: 100vh;
    transform: skewY(5deg);
    box-sizing: border-box;
    padding: 100px;
    position: relative;
    top: -120px;
    overflow: hidden;
}
.tor {
    width: 100%;
    height: 100%;
    transform: skewY(-5deg);
    background-image: url(http://unsplash.it/800/500);
    background-size: cover;
    background-position: center;
    position: absolute;
    left: 0;
    top: 0;
    padding: 100px;
}
.c {
    width: 100%;
    padding: 50px;
    height: 300px;
    box-sizing: border-box;
    top: -50%;
    transform: translateY(-50%);
    position: relative;
    text-align: center;
}
.c::after {
    content: "";
    width: 100%;
    height: 300px;
    background-color: navy;
    left: 0;
    top: 0;
    transform: skewY(-5deg);
    position: absolute;
    z-index: -1;
}
.box {
    background-color: aliceblue;
    width: 120px;
    height: 100px;
    margin: 20px;
    position: relative;
    display: inline-block;
}
<div class="s">
    <div class="tor">
        <h1>Lorem ipsum dolor sit.</h1>
    </div>
</div>
<div class="c">
    <div class="box">
        oi
    </div>
    <div class="box">
        oi
    </div>
    <div class="box">
        oi
    </div>
</div>

2


Create 2 Divs, one that will be the container of the other:

<div class="skew">
    <div>Texto</div>
</div>

and set the style of the first with the skewY desired:

-ms-transform: skewY(-12deg);
-webkit-transform: skewY(-12deg);
transform: skewY(-12deg);

and for the div 'daughter', undo the Transform, to correct the contents:

-ms-transform: skewY(12deg);
-webkit-transform: skewY(12deg);
transform: skewY(12deg);

check out the snippet:

.skew{
	margin-top:100px;
	background: black;
	display:inline-block;
	-ms-transform: skewY(-12deg);
	-webkit-transform: skewY(-12deg);
	transform: skewY(-12deg);
}
.skew>div {
	padding: 50px 100px;
	font: 30px/1 sans-serif;
	-ms-transform: skewY(12deg);
	-webkit-transform: skewY(12deg);
	transform: skewY(12deg);
	color: white;
}
<div class="skew">
	<div>Texto</div>
</div>

just adapt your need

1

I believe you did the right thing, all you had to do was hide what’s left

#pai {
  overflow: hidden;
}
#filho {
  background-color: skyblue;
  transform: rotate(-5deg);
  margin: 50px -15%;
}
#texto {
  margin-left: 15%;
  transform: rotate(5deg);
  line-height: 150px;
}
<div id="pai">
  <div id="filho">
    <div id="texto">um texto qualquer de teste centraalizado verticalmente</div>
    </div>
</div>

Browser other questions tagged

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