Tailwind CSS skew cards
permalinkTailwind is a fantastic CSS framework. It makes it so easy to create cool designs without much effort.
Today I want to create something very basic but widely used: Skew cards.
They are cards that are skewed in a specific direction, and the offset is the skewed opposite.
It looks like this:
Creating Tailwind skew cards permalink
For our basic skew card, we need 2 div elements and some content in the inner one.
<div>
<div>
<h2>Tailind Skew Cards</h2>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Adipisci ex vitae sequi
nostrum quidem vero odio repudiandae expedita, quis aliquam?
</p>
</div>
</div>
This will be our main structure. Let's add the outer classes first.
<div class="transform skew-y-3 bg-purple-200 p-8 w-1/2"></div>
The main part is the transform and skew class. This will make sure the card looks slanted. Then we add a simple background, padding, and width.
Now our card will look somewhat weird:
The text also went skew, which is not what we want. However, we can offset this in the inner div.
<div class="transform -skew-y-3"></div>
And that's it, we now got our first skew card.
We can also have them skew the other way by reversing the skews.
<div class="transform -skew-y-3 bg-purple-200 p-8 w-1/2">
<div class="transform skew-y-3">
<h2 class="text-lg">Tailind Skew Cards</h2>
<p>
Lorem, ipsum dolor sit amet consectetur adipisicing elit. Adipisci ex vitae sequi
nostrum quidem vero odio repudiandae expedita, quis aliquam?
</p>
</div>
</div>
You can find the full demo on the following Codepen.
See the Pen Tailwind CSS skew cards by Chris Bongers (@rebelchris) on CodePen.
Thank you for reading, and let's connect! permalink
Thank you for reading my blog. Feel free to subscribe to my email newsletter and connect on Facebook or Twitter