Re:How We Could Write Better CSS
by ryanSrich on Tuesday September 24, 2013 @01:14PM
(#6439237)
I find that following a prefix method works quite well for organizing a lot CSS. For example (using sass):
This helps keep classes out of your HTML and avoids large amounts of nested CSS. Here's the compiled source:
[ Parent
| on HN ]
But with classes with "green" and "blue" in the names, you're still mixing meaning and presentation and hurting maintainability. See: http://thecodelesscode.com/case/95
Just nit picking here, but I think your selectors are a bit redundant and long. What do you think about something like this?
.home-header-h1{
font-size: 20pt;
padding: 0px;
margin: 0px;
line-height: 1.3;
}
h1.home-blue{
@extend .home-header-h1;
color: blue;
}
h1.home-green{
@extend .home-header-h1;
color: green;
}
But I think if I was trying to truly minimize maintenance I would do something like... (in LESS not familiar with sass) h1.home {
font-size: 20pt;
padding: 0px;
margin: 0px;
line-height: 1.3;
&.blue {
color: blue;
}
&.green {
color: green;
}
}