How to leave a pie div? [duplicate]

1

Hello, I recently found a layout in Google and found the idea very interesting, but I do not know how to reproduce the div that way, it's basically to make the div 'crooked', I tried to reproduce but when I used rotate ), the div bent but was not glued on both sides, even with width: 100%; so I'll post the layout here and would appreciate if someone would show me how to do the same thing on one of those divs.

    
asked by anonymous 12.05.2018 / 04:24

3 answers

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 to the desired transform of skewY :

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

and for the 'daughter' div, undo the transform, to 'fix' the content:

-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

    
12.05.2018 / 05:46
2

I made a simple example, using skew only in elements ::after and ::before . So I make an X with the elements, and the main content does not even have to use skew to correct. Note that z-index is also used because ::after is above the image and ::before below

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, by inverting values of skew between parent and child, and another technique using skew only in ::after

Here in the Stackoverflow Snippet it will not work well, but then you can test it in 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>
    
13.05.2018 / 18:06
1

I think I did it right, I just needed to hide the part that is left over.

#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>
    
12.05.2018 / 05:38