Re:Abusing CSS3's nth-child selector to invent new ones
by Alex3917 on Friday January 09, 2015 @01:15PM
(#8863449)
Be careful with nth-child -- my advice is to only use it with lists where every item is of the same type. It's tempting to start using it with things like tables to style your rows super quickly, but then the second you need to add a single row or column then everything breaks and you need to spend half the day fixing something that should have taken about 5 minutes.
[ Parent
| on HN ]
Re:Abusing CSS3's nth-child selector to invent new ones
by 91bananas on Friday January 09, 2015 @01:44PM
(#8863614)
For this reason I am much more a fan of nth-of-type, and all of the -of-type's, since they actually look at the element type and can say, I should style this one but not anything else that may appear at the same level.
Re:Abusing CSS3's nth-child selector to invent new ones
by mmastrac on Friday January 09, 2015 @02:25PM
(#8863910)
I'm really looking forward to CSS selectors level 4. That spec will include a new parameter to nth-child: nth-child(3 [of S]), where S can be any further selector.
Re:Abusing CSS3's nth-child selector to invent new ones
by kmz on Saturday January 10, 2015 @12:10AM
(#8865984)
Actually just found out about -of-type's, very powerful.
Re:Abusing CSS3's nth-child selector to invent new ones
by psychometry on Friday January 09, 2015 @08:19PM
(#8865452)
Since most tables are generated programmatically these days, it's probably easier just to use classes for this kind of styling. And it seems a lot of people forget about the <colgroup> HTML element, which makes it easy to style columns without adding classes to every table cell.
Re:Abusing CSS3's nth-child selector to invent new ones
by slang800 on Saturday January 10, 2015 @01:59AM
(#8866192)
It's probably even easier to just put inline styles on every row, but neither of those practices are going to result in maintainable markup.
By adding classes for the singular purpose of styling them, you tie your markup to the appearance of the web page. Instead, classes should be used to further describe the contents of elements in relation to each other. Then all the presentational rules can be kept in CSS, and selectors can be used to style based on the meaning of the content.
This means the style of the page can change without modifying the markup. And if the styles are written well enough, they can be applied to any (sane) markup.
Oh and +1 for colgroup!