I saw the below design and would like to implement something similar in my web application, but how do I make the div tilted on the top (as shown in the image)?
<div class="" style="height: 100vh; background-color: white"></div>
<div class="" style="height: 100vh;position: relative; border: 2px solid black;">
<div class="" style="height: calc(50% + 2rem);background-color: white;"></div>
<div class="" style="height: calc(50% - 2rem);background-color: blue;"></div>
<h1 style="position: absolute; top: 50%; z-index: 9; transform: translateY(-50%); transform: rotate(-2deg); text-align: center;width: 100%; background-color: yellow; height: 4rem">WELCOME TO OUR WEBSITE</h1>
</div>
<div class="" style="height: 100vh; background-color: blue"></div>
I also tried tailwind skew and transform rotate but there was no luck I got a horizontal scrollbar and there is white space after turning the div
Expected:
Similar to the first image I posted, I want to make a proper responsive tilted div using tailwind. It should be full width tilted on the top with a two-tone color and a straight bottom.
2
Answers
You need to combine transformations: the translateY(-50%) and rotate(-2deg). Below code will help you
This turned out to be more difficult than I anticipated. I found only one relatively responsive approach.
There are two challenges:
overflow: hidden
cannot be applied exclusively to the x-axis or y-axis. Ifoverflow: hidden
is applied in one direction, it hides overflow in both directions.Solutions:
overflow: clip
to hide overflow in only the x direction.Demo on Tailwind Play.
In the example, I used red and blue to differentiate between the filling elements and the main content. In actual use, they should be set to the same color.