One of my favorite not-so-new aspects of CSS is the You can use this to target elements that have no children—either child elements or whitespace and text nodes—and style them differently than they would be otherwise. For example, imagine you have some CSS to layout items in a row using flexbox…
And a row of items generated from an API or database or something. Since you don't know the content ahead of time, it's possible that one of the items may have no content in it, like the fourth
That empty In situations like this, you can use the
Now, the empty yellow box is hidden in the UI. Here's another demo. A lot of developers will reach for JavaScript DOM manipulation for stuff like this. But CSS provides a simpler, easier, and less error-prone way to handle the same thing. Like this? A Lean Web Club membership is the best way to support my work and help me create more free content. Cheers, Want to share this with others or read it later? View it in a browser. |
0 Komentar untuk "[Go Make Things] The :empty pseudo-class in CSS"