Why BEM Nesting Breaks in Tailwind v4

So today I spent sometime debugging why some CSS styles weren't applying. Turns out, Tailwind v4 quietly broke something on was working Tailwind v3. What happened I had CSS like this: .dropdown { b...

By · · 1 min read
Why BEM Nesting Breaks in Tailwind v4

Source: DEV Community

So today I spent sometime debugging why some CSS styles weren't applying. Turns out, Tailwind v4 quietly broke something on was working Tailwind v3. What happened I had CSS like this: .dropdown { background: white; &--open { background: blue; } &__icon { width: 16px; } } In Tailwind v3, this worked perfectly. It would compile to: .dropdown { background: white; } .dropdown--open { background: blue; } .dropdown__icon { width: 16px; } But in Tailwind v4? Nothing. No error. No warning. It just silently does nothing. Meanwhile, this still works fine: .dropdown { &:hover { background: gray; } & .child { color: red; } } Wait, what? &:hover works but &--open doesn't? Why?? The reason It comes down to native CSS nesting vs SASS nesting. Native CSS (what browsers understand) supports & only for: Pseudo-classes: &:hover, &:focus, &::before Combinators: & .child, & > .child, & + .sibling Chaining: &.another-class SASS added an extra featur

Similar Topics

#ai (16747) #machine learning (14680) #programming (3999) #python (1819) #security (717) #productivity (375) #automation (335) #devops (314) #beginners (289) #javascript (229) #opensource (171) #tutorial (153) #api (110) #startup (108) #performance (103) #retrieval augmented (84) #career (74) #typescript (66) #showdev (66) #react (63)

Related Posts

Trending on ShareHub

Latest on ShareHub

Browse Topics

#artificial intelligence (31552) #data science (24017) #ai (16738) #generative ai (15034) #crypto (14987) #machine learning (14680) #bitcoin (14229) #featured (13550) #news & insights (13064) #crypto news (11082)

Around the Network