CSS---通向臃肿的道路(关于 “separation of concerns” (SoC)的原则)

前端之家收集整理的这篇文章主要介绍了CSS---通向臃肿的道路(关于 “separation of concerns” (SoC)的原则)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

  

<h3 id="the-path-to-bloat">The Path To Bloat

Because the styles of our module are tied only to presentational class names, they can be anything we want them to be. For example,if we need to create a simple two-column layout,all we need to do is replace the link with a div in our template. That would look like this:

=>
=>
=>

And we would need only one extra rule in the style sheet:

-------%

Compare this to the traditional way:

=>
=>
=>

This would require us to create three new classes,to add an extra rule and to group selectors.

%-

I think the code above pretty well demonstrates the price we pay for following the SoC principle. In my experience,all it does is grow style sheets.

Moreover,the larger the files,the more complex the rules and selectors become. And then no one would dare edit the existing rules:

  • We leave alone rules that we suspect to be obsolete for fear of breaking something.
  • We create new rules,rather than modify existing ones,because we are not sure the latter is 100% safe.

In other words,we make things worse because we can get away with bloat.

Nowadays,people are accustomed to very large style sheets,and many authors think they come with the territory. Rather than fighting bloat,they use tools (i.e. preprocessors) to help them deal with it. :

"LinkedIn has over 1,100 Sass files (230k lines of SCSS) and over 90 web developers writing Sass every day."    

猜你在找的CSS相关文章