Loading video...

Video Failed to Load

Go Home

๐Ÿ”ฅ Tailwind Tip ๐Ÿ”ฅ Create a "color background split" effect with CSS Grid. It greatly simplifies the spacing adjustment gymnastics you need to do when using transforms to translate your element across both sections โœจ

127,868 views โ€ข 3 years ago โ€ขvia X (Twitter)

10 Comments

Simon Vrachliotis's profile picture
Simon Vrachliotis3 years ago

I've used this exact technique on the homepage of the new @thethinkmill website. You can check it out here: โœจ

Simon Vrachliotis's profile picture
Simon Vrachliotis3 years ago

If you liked this, I have a @ProTailwind tutorial in the works that goes in **a lot more depth** about using CSS grid to control background color splits. I plan to release this tutorial **for free**, like the existing "Ribbon Banner" tutorial available at

Simon Vrachliotis's profile picture
Simon Vrachliotis3 years ago

๐Ÿ‘€

Simon Vrachliotis's profile picture
Simon Vrachliotis3 years ago

The reason the grid bands use half the height each is because our grid is using position: absolute with inset-0, making it occupy all the space of its relative parent. Each grid row uses "1fr" of space. If we had 4 divs inside that grid, they would each share 1/4 of the height!

Simon Vrachliotis's profile picture
Simon Vrachliotis3 years ago

Here's a link to the Tailwind Play used in this video:

Siddhartha Gudipati's profile picture
Siddhartha Gudipati3 years ago

Or alternatively, you could just use a gradient with 50% background: linear-gradient(180deg, white 50%, cyan 50%, cyan 50%);

Chico Sousa's profile picture
Chico Sousa3 years ago

I learn more CSS using @tailwindcss. Never heard of isolate prop.

Simon Vrachliotis's profile picture
Simon Vrachliotis3 years ago

@and3rsonsousa @tailwindcss It creates a new stacking context explicitely, and not as a "side effect" like using relative or another stacking context triggering property ๐Ÿ‘

Keebinhand โŒจ๏ธ's profile picture
Keebinhand โŒจ๏ธ3 years ago

Nice. I usually reach for background gradients with a hard edge.

Simon Vrachliotis's profile picture
Simon Vrachliotis3 years ago

Ah yep this is also a good technique, 0 to 50, and 50 to 100 ๐Ÿ‘

Related Videos

CSS Tip! ๐Ÿ’ช You can create these tab controls with CSS :has() + radio buttons โœจ .tabs:has(input:nth-of-type(3)) { --count: 3; } .tabs:has(:checked:nth-of-type(3)) { --active: 2; } .tabs::after { translate: calc(var(--active, 0) * 100%) 0; width: calc(100% / var(--count)); } Two CSS :has() tricks here combined with a rendering trick ๐Ÿค™ The tab control is a container using display: grid. You can use :has() to count the number of tabs in the container: .tabs:has(input:nth-of-type(3)) { --count: 3; } .tabs:has(input:nth-of-type(4)) { --count: 4; } Using the cascade, the last valid :has() gives you the number of tabs ๐Ÿซถ Once you know the number of tabs, you know how to size the indicator: .tabs::after { content: ""; position: absolute; height: 100%; width: calc(100% / var(--count)); } It's a pseudoelement that uses --count to determine its size ๐Ÿ“ The next :has() trick is determining which tab is active or :checked as it's an input [type=radio] .tabs:has(:checked:nth-of-type(2)) { --active: 1; } .tabs:has(:checked:nth-of-type(3)) { --active: 2; } You can use a zero-indexed translation here. If the second input is :checked, set --active: 1, then translate the pseudoelement on the tabs to that position ๐Ÿ‘‰ .tabs::after { translate: calc(var(--active, 0) * 100%) 0; } The last rendering trick is using mix-blend-mode ๐Ÿ‘€ The tabs have a black background-color, the pseudoelement is white, and the label text is white. When you use mix-blend-mode: difference on the pseudoelement it will give this effect that the text transitions from white to black sliding across ๐Ÿ˜Ž .tabs::after { color: hsl(0 0% 100%); mix-blend-mode: difference; } You can totally mix up the colors here though and go with a different effect. The mechanics of how you can use CSS :has() is the main point here ๐Ÿ™ As always, any questions, suggestions, etc. let me know CodePen.IO link below! ๐Ÿ‘‡ (There's even a Tailwind CSS play for this one too ๐Ÿ‘€)

jhey ส•โ€ขแดฅโ€ขส”

437,300 views โ€ข 2 years ago