正在加载视频...

视频加载失败

🔥 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 次观看 • 3 年前 •via X (Twitter)

10 条评论

Simon Vrachliotis 的头像
Simon Vrachliotis3 年前

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

Simon Vrachliotis 的头像
Simon Vrachliotis3 年前

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 的头像
Simon Vrachliotis3 年前

👀

Simon Vrachliotis 的头像
Simon Vrachliotis3 年前

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 的头像
Simon Vrachliotis3 年前

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

Siddhartha Gudipati 的头像
Siddhartha Gudipati3 年前

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

Chico Sousa 的头像
Chico Sousa3 年前

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

Simon Vrachliotis 的头像
Simon Vrachliotis3 年前

@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 ⌨️ 的头像
Keebinhand ⌨️3 年前

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

Simon Vrachliotis 的头像
Simon Vrachliotis3 年前

Ah yep this is also a good technique, 0 to 50, and 50 to 100 👍

相关视频

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 次观看 • 2 年前