How We Could Write Better CSS
colmtuite.com
How We Could Write Better CSS
1–10 of 55 posts
Re: How We Could Write Better CSS
#2Re: How We Could Write Better CSS
#3We need this. I've been thinking the same thing as the author for quite some time, I'm glad someone has at least put the idea out there.
Re: How We Could Write Better CSS
#4Edit: your site's visual design is awesome, btw
Re: How We Could Write Better CSS
#5This also enables inconsistent UI in the front-end: some of my page-headers can have .mbl "Large bottom margins" and some could have .mbs "Small bottom margins".
Re: How We Could Write Better CSS
#6Re: How We Could Write Better CSS
#7Re: How We Could Write Better CSS
#8If you are injecting your markup elements with classes like "mbm mts mrl" (or padding, or anything else that is essentially just a css property), this is not much different than just inlining your styles. If you want this level of reusability in your css, use sass and create these as placeholders. From there give your dom element a some kind of class(es) that can extend several of these placeholder values.
Ian Storm had a very well written article that hits on this more: http://ianstormtaylor.com/oocss-plus-sass-is-the-best-way-to...
Re: How We Could Write Better CSS
#9 .home-header-h1{
font-size: 20pt;
padding: 0px;
margin: 0px;
line-height: 1.3;
}
.home-header-h1-blue{
@extend .home-header-h1;
color: blue;
}
.home-header-h1-green{
@extend .home-header-h1;
color: green;
}
This helps keep classes out of your HTML and avoids large amounts of nested CSS. Here's the compiled source: .home-header-h1, .home-header-h1-blue, .home-header-h1-green {
font-size: 20pt;
padding: 0px;
margin: 0px;
line-height: 1.3; }
.home-header-h1-blue {
color: blue; }
.home-header-h1-green {
color: green; }Re: How We Could Write Better CSS
#10Deeply nested CSS selectors in the source (like the ones in your MixPanel examples) are often a sign of CSS preprocessors in use. Using a tool like LESS or Stylus, MixPanel is probably including mixins in their styles that allow them the same modular flexibility you describe without cluttering the HTML with confusing, non-semantic classes like "mrm". Edit: your site's visual design is awesome, btw
Just because the output isn't 100% optimal doesn't mean the input isn't sane, maintainable, or clean.