When you use floats to generate a grid, you may have "orphans" — nodes at the end that do not form a complete row. Perhaps you would like to style them differently or hide them! I found a way to do this using only CSS. The catch? You need to write a selector for each individual orphan element. That means in rows of 4 elements, you'll need 3 selectors. Still pretty darn useful. CSS is powerful!
Last active
December 15, 2015 05:39
-
-
Save potch/5210723 to your computer and use it in GitHub Desktop.
Using CSS to target orphan nodes of a grid.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* The CSS for targeting trailing nodes in a grid with rows of 4 nodes */ | |
div:nth-last-child(-n+3):nth-child(4n+1), | |
div:nth-last-child(-n+2):nth-child(4n+2), | |
div:nth-last-child(-n+1):nth-child(4n+3) { | |
background: blue; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment