Home › Forums › CSS › Structural pseudo-classes vs ID’s & classes › Re: Structural pseudo-classes vs ID’s & classes
I think we’ll always have to use classes and IDs, and replacing them with nth-child
isn’t really an alternative, even though technically it would work.
What we’re used to:
(header here)
(content here)
(sidebar here)
(footer here)
You could replace that with:
(header here)
(content here)
(sidebar here)
(footer here)
…and then target the divs with div:nth-child(1)
to div:nth-child(4)
.
However, it makes the markup code very non-semantic, which is also not great for SEO, and such.
Also, maintenance is going to be tedious. For example, if you want to insert a new div before the header? Then all the numbers go up with one (they are now div:nth-child(2)
to div:nth-child(5)
), whereas with the old method, you just add in a div before the header and you didn’t have to do anything with all the others.
So yea, it can be done, but I don’t think it should.