When it comes to CSS, I believe that the sacred principle of “separation of concerns” (SoC) has lead us to accept bloat, obsolescence, redundancy, poor caching and more. Now, I’m convinced that the only way to improve how we author style sheets is by moving away from this principle.

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:

<div class="Bfc M-10"><div class="Fl-start Mend-10 W-25">column 1</div><div class="Bfc">column 2</div>
</div>

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

.Bfc {overflow: hidden;zoom: 1;
}
.M-10 {margin: 10px;
}
.Fl-start {float: left;
}
.Mend-10 {margin-right: 10px;
}
.Fz-s {font-size: smaller;
}
.W-50 {width: 50%;
}

Compare this to the traditional way:

<div class="wrapper"><div class="sidebar">column 1</div><div class="content">sidebar</div>
</div>

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

.wrapper,
.content,
.media,
.bd {overflow: hidden;_overflow: visible;zoom: 1;
}
.sidebar {width: 50%;
}
.sidebar,
.media .img {float: left;margin-right: 10px;
}
.media .img img {display: block;
}

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. Chris Eppstein tells us:

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

转载于:https://www.cnblogs.com/JesseP/p/10248078.html

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

  1. tyvj1467 通向聚会的道路

    背景   Candy住在一个被划分为n个区域的神奇小镇中,其中Candy的家在编号为n的区域,Candy生日这天,大家都急急忙忙赶去Candy家庆祝Candy的生日. 描述   Candy共有t个朋友 ...

  2. 捍卫者usb管理控制系统_捍卫效用优先CSS

    捍卫者usb管理控制系统 by Sarah Dayan 通过莎拉·达扬 捍卫效用优先CSS (In Defense of Utility-First CSS) "Favor composit ...

  3. 专访黄勇:Java在未来的很长一段时间仍是主流

     专访黄勇:Java在未来的很长一段时间仍是主流 发表于2015-09-06 13:18| 11640次阅读| 来源CSDN| 70 条评论| 作者钱曙光 社区文旦专访黄勇架构框架JavaJava ...

  4. 一个10年IT技术人的历程-Java架构师的演变

    原文:专访黄勇:Java在未来的很长一段时间仍是主流 摘要: 本文采访了现任阿里巴巴公司系统架构师黄勇,从事近十年的JavaEE应用开发工作.采访内容包含了技术人生.IT职场.程序员.Java Web ...

  5. JavaScript面试题集锦

    JavaScript面试题集锦 1.js基础 1.eval是做什么的? 它的功能是把对应的字符串解析成JS代码并运行: 应该避免使用eval,不安全,非常耗性能(2次,一次解析成js语句,一次执行). ...

  6. Prefactoring——Guidelines

    Prefactoring--Guidelines Prefactoring--Introduction Introduction 虽然Prefactoring这个概念并无多少新意(个人看法),但Ken ...

  7. ajax async:false不管用_js 网络请求框架 ajax和axios、fetch的区别

    互联网行业发展至今出现了很多技术,技术都在与时俱进的更新中,如从前的前端技术栈(html4+js+css+jquery)到现在vue+axios.随着更多优秀的框架出现,让我们从重复的基础代码编写中解 ...

  8. sass导入sass_如何使用Sass Mixins和Loops

    sass导入sass by Jason Arnold 杰森·阿诺德(Jason Arnold) 如何使用Sass Mixins和Loops (How to use Sass Mixins and Lo ...

  9. 面向对象编程,设计原则,设计模式

    2019独角兽企业重金招聘Python工程师标准>>> 面向对象编程,设计原则,设计模式 面向对象编程 面向对象编程与面向过程编程的区别 面向对象软件开发的优点 面向对象编程语言 C ...

  10. 比程序员更好的职业_立即成为更好的程序员的20条技巧

    比程序员更好的职业 目录: (Table of contents:) Think Before You Code 编码前先思考 Understand the Business Behind Every ...

最新文章

  1. VSS2005下载地址
  2. Unix目录结构的来历
  3. Openwrt中luci配置页面cbi小记
  4. PCB生成光绘文件教程 (Z)
  5. js使用工具将表单封装成json字符串传到后台,js截取字符串(学生笔记)
  6. numpy读取csv_Numpy——IO操作与数据处理
  7. LeetCode 1452. 收藏清单(std::includes判断子集)
  8. android 导航自动切换,Android导航抽屉切换图标向右
  9. java反射——构造方法
  10. 愿你我,能被这世界温柔以待
  11. 电气防火限流式保护器及其过电流故障检测方法
  12. Windows Message ID
  13. matlab 渐变色
  14. 谢宁方法或谢宁DOE
  15. 公司网页服务器访问超时,网站页面请求后台超时的相关咨询
  16. 【JZOJ6150】爱乐之城
  17. OSDU(Open Group Open Subsurface Data Universe)数据平台研究笔记
  18. 读书有益——》摆渡人
  19. java服务和net服务_艾伟_转载:Java和.NET互操作:我们应该放弃Web Service吗?
  20. Star CCM+ 案例 - 旋风分离器 (cyclone separator)-3 模拟设置

热门文章

  1. 可以同情弱者,别同情弱势!
  2. 科技爱好者周刊(第 163 期):你的城市有多少张病床?
  3. Neo4j学习笔记-Embedded嵌入模式简单示例
  4. 阿里云域名优惠口令获取及使用方法
  5. linux编译openssl报错,cargo编译musl报错openssl
  6. 管理者如何做好团队规划
  7. Microsemi Libero系列教程(一)——Libero开发环境介绍、下载、安装与注册
  8. NVI(Non-Virtual Interface )
  9. 360浏览器登录新浪微博图标显示为字母及占用CPU过高问题的解决
  10. WWW 2019 | HAN:异质图注意力网络