CSS样式表有一个随着时间的推移而变大和混乱的习惯。
有很多规则,提示和学校的想法,有助于实现更清洁的CSS。 (例如here)然而,所有这些都需要持续的警觉性,活动和维护者的很多纪律,与现实世界的成功混合。为Nicole Sullivan so nicely puts it:
In fact, in most cases, the things we considered best practices were leading to the bad outcomes we sought to avoid. I realized (unpopular though it might be), that we couldn’t make it work out well by trying harder. Each time we start a new project, we think “this time, I’m going to keep the code clean. This time the project will be a shining example of what can be done with CSS.” And without fail, over time, as more content and features are added to the site, the code becomes a spaghetti tangle of duplication and unpredictability.
有没有努力创建某种语言,有严格的结构规则和无情的编译器,强制执行严格的规则,防止样式表成为意大利面条?编译的最终结果将是CSS。
我不知道这样的语言会是什么样子,考虑到大量的可能性和组合,这是一个可解决的问题。
这个领域有没有研究?什么都试试?
一个非常有趣的相关工具是CSS Lint,但我要求的是甚至比这更远。
Edit: LESS and SASS absolutely go into the right direction, but they are not what I am looking for. They introduce some very nice features and are a godsend for the CSS developer, but what I’m, asking about goes even further and more into defined, enforced structures.