4 ms·
> A project might easily have 50 different ".title" classes, but you know you don't have to worry about collisions. Not if your UI is of sufficient complexity
by peterhunt 13y ago
> A project might easily have 50 different ".title" classes, but you know you don't have to worry about collisions.
Not if your UI is of sufficient complexity that you're composing components of other components. Then not only do you have lots of collisions, you have a huge specificity war too. That's why prefixing and single-class-name selectors are generally preferred.
- crazygringo 13y agoOf course. Nesting is just a tool that helps organize your classes. I've found the most maintainable code comes from a well-defined combination of nesting and prefixes (but I tend to use nesting as a default, and prefixes only when necessary) -- they both have their strengths and weaknesses. But CSS precedence is always a problem, if it's not specificity then it's ordering instead, the problem doesn't go away by using prefixes. But using the order that rules are defined in can often be more difficult to track/maintain than using specificity to do the same. Good commenting practice is key in both cases. Nesting with mixins certainly isn't always the answer, but it often provides a much cleaner, more maintainable, more intuitive approach to resolving occasional "specificity wars" than not using them.