3 ms·
What's the point of creating a class called 'margin-b10'? Why not just inline your CSS, i.e. style="margin-bottom:10px;"? Creating a class called margin-b10 is
by dheera 11y ago
What's the point of creating a class called 'margin-b10'? Why not just inline your CSS, i.e. style="margin-bottom:10px;"?
Creating a class called margin-b10 is tantamount to the following C code:
int one = 1, two = 2, three = 3;
And then using 'one', 'two', and 'three' instead of 1, 2, 3.
- Semiapies 11y agoHorribly, that sort of thing has been done by inexperienced programmers told to use constants instead of hard-coding numbers into their code...
- WiseWeasel 11y agoBecause there are a few paddings and margins that are used repeatedly, and it's convenient. Clearfixes and floats are another common use case. An anchor that I want to look like a button might have classes like "button orange float-r margin-r20".
- dheera 11y agoIf you're repeatedly using 10px paddings, it doesn't really save anything to name your classes 'padding-10px'. Inlining your CSS is just as efficient. Plus, if you have to change your styling, e.g. from 10px to 12px, all of a sudden you have to change both the definition of the class AND the name of the class, which is a mess. And if you don't, you have a class called 'padding-10px' that is actually 12px and that is a real mess. If you're naming your classes to create abstractions, i.e. 'article-box' or 'navbar-section' then it makes a lot more sense.