`
love~ruby+rails
  • 浏览: 852452 次
  • 性别: Icon_minigender_1
  • 来自: lanzhou
社区版块
存档分类
最新评论

Why Stylesheet Abstraction Matters

阅读更多

I’ve seen a number of comments on blogs and twitter that amount to “You don’t need a new stylesheet syntax, CSS is simple and you’re a moron if you can’t do it.” I agree, CSS is simple. You assign style primitives to elements and some of those primitives cascade down to the elements contained within. I get it. It’s simple to understand. But CSS is not simple to use or maintain. It’s time for stylesheets to evolve so that we can take web design to the next level.

Over the past few years the development of JavaScript frameworks have brought sanity to coding against the DOM – optimizing common coding tasks through the creation of abstractions than insulate us from the nitty-gritty details and providing a common platform for third-party libraries to rely on. As a result, it’s a very nice time to be a front-end programmer. It’s been a couple of years since I’ve bitched about DOM incompatibilities – long enough to almost forget how much work it used to be. It’s also a very nice time to be a user of the web, freed of the need to fuss with DOM primitives and JavaScript intricacies, developers have turned their spare time into much more sophisticated user interfaces.

Creating and maintaining the styles of a website, by comparison, is a total pain in the ass. I’m not talking about the lack of a decent layout module for CSS. I’m talking about the fact that CSS lacks the expressive nature required to create abstractions. The simplicity of the CSS syntax creates complexity for the developer. Every time you have to copy and paste something within your stylesheet instead of reference that same information, you’ve missed an opportunity to make your stylesheets easier to maintain through abstraction. However, if you’ve ever tried to build a DRY stylesheet, you’ve found that the only tool at your disposal is the “class” construct. So the DRYest stylesheet will necessarily force you to put all kinds of presentation classes in your markup, thus making your website less maintainable. Case in point: Shared html partials & includes may need to be styled differently in different contexts.

Let’s be frank, your designs are going to change. New features will be added that make you reevaluate things. You’ll decide you hate some color or font treatment. Your HTML is going to change. New browsers are going to come out with new quirks. Any every time something changes, you have to propagate that change across your stylesheets. If you’re lucky, you can search and replace for the change. But what if you want to change the color #000 to #333? You can’t search and replace for #000. First, you could have usedblack or #000000 or rgb(0,0,0). Second, it’s likely that black is used for other things than what is changing. But what if you had named that color? Now that black is different from all the other blacks. It’s now the “article font color” and changing that abstraction can be done once and propagated for you by a smarter stylesheet syntax.

CSS is the weakest link in the web developers toolbox. The problem goes deeper than CSS’s lack of variables. Unlike the “function” in programming, CSS has no fundamental building block.

What Is Abstraction?

Abstraction is the ability to define a new concept in terms of other, more simple concepts. It’s nothing to be scared of. When you define a CSS class, you are creating an abstraction. Despite what the name implies, abstractions don’t make things harder to understand – quite the opposite in fact.

Why You Should Care About Demand Abstraction

Just because a website is digital, doesn’t mean it is intangible. It is a real thing that users can see and interact with. And although there’s a lot of code sitting behind a web page to make it work, it is the act of designing that makes a website concrete. It is the designer’s job to build real objects that users intuitively understand. Search boxes, articles, advertisements, navigation, and so on. But the browser doesn’t know what these things are. The browser only understands primitives like font-size, border, padding, images, tags, etc.

So it is the designer’s job to transform the primitive design concepts that a browser understands into real things. This is done by defining new abstractions that never existed before. They are not abstract to us, rather they are abstract to the browser. So when a language gives you the power of abstraction, it gives you the power to build real things. And that is your job. And that is why you should care about, nay, demand a stylesheet syntax that gives you the power of abstraction.

Parts is Parts

No finished product of sufficient complexity is built without first creating intermediate parts. Let’s consider an automobile for example. There are belts, wires, alternators, gears, etc. When a car maker wants to build a car, they don’t build belts and gears. They specify what kind of belts and gears they need and they get them from a third party. No one would think less of BMW for doing so.

We have the same in web design. Grids, buttons, tabs, menus, font rhythm, etc are all considered standard elements for a website. But for the most part, we don’t get their implementation from a third party. When we do, it’s generally viewed with disdain. I think this is unacceptable. Once certain design elements become commodity, there is no reason for you to waste your time building them anymore. You should focus your time on the unique aspects of your design.

Unfortunately, with CSS it’s hard to compose a design from third-party parts. They are hard to customize and once customized, hard to upgrade if there are bugs that need to be fixed. Clearly there must be a better way.

more:

分享到:
评论

相关推荐

    StyleSheet

    StyleSheet、StyleSheet

    Qt5-stylesheet-样式表

    **Qt5 样式表(Qt5 StyleSheet)详解** 在Qt框架中,样式表(StyleSheet)是一种强大的工具,用于自定义应用程序的外观和感觉。它类似于网页开发中的CSS(层叠样式表),允许开发者通过简单的语句来改变控件的视觉...

    Qt利用StyleSheet更改大部分默认控件外观

    Qt 中使用 StyleSheet 实现控件外观自定义 Qt 是一个功能强大且灵活的 GUI 库,提供了丰富的样式表机制,允许开发者轻松地自定义控件的外观。通过使用 Qt StyleSheet,可以轻松地改变大部分默认控件的外观,从而...

    css转stylesheet插件,适用于鸿蒙、RN.zip

    在这样的背景下,"css转stylesheet插件,适用于鸿蒙、RN.zip" 提供了一个解决方案,帮助开发者更高效地在鸿蒙系统和React Native(RN)中应用CSS样式。 首先,我们要理解CSS(Cascading Style Sheets)在Web开发中...

    stylesheet

    安装WINCC勾选消息队列时需要安装的系统组件,下载下来和大家分享。

    stylesheet.zip

    在"stylesheet.zip"这个压缩包中,包含了一个关于QSS界面美化的实例,这对于想要提升自己程序界面美观度的学习者来说是一个很好的起点。 QSS允许开发者用类似CSS的语法定义Qt控件的外观和布局,如颜色、字体、边框...

    Qt5stylesheet

    在Qt5环境中,`Qt5stylesheet`是一个强大的特性,它允许开发者通过CSS样式的语法来定制应用程序的界面外观。这使得Qt应用的界面设计变得更加灵活和多样化,可以轻松实现窗口背景色、控件背景色以及其他视觉元素的...

    Qt StyleSheet 样式表实例

    Qt样式表(StyleSheet)是Qt中的一个重要概念,类似于网页设计中CSS的作用,允许开发者通过声明式的方法来控制Qt应用程序中控件的样式。Qt样式表的使用能够大大提高界面的可定制性,而且有助于保持代码的清晰和组织...

    Qt stylesheet

    Qt Stylesheet是Qt框架中一个强大的特性,它允许开发者通过CSS样式语法来定制Qt应用程序的外观和感觉。这篇详尽的介绍将深入探讨Qt Stylesheet的相关知识点,帮助新学习者快速掌握这一技能。 首先,Qt Stylesheet...

    qt黑色styleSheet样式表

    QT界面开发 样式挑战

    stylesheet:使用JavaScript创建sylesheets

    bower install stylesheet --save-dev使用范例 var stylesheet = new StyleSheet ( ) ;// Specify the selector to work on.stylesheet . setSelector ( '.pause-hud' ) ;// Insert rules.stylesheet . insertRule ...

    浏览器默认样式(User Agent Stylesheet)的介绍与最佳处理方法

    如果对这个默认样式不满意最简单的解决办法就是重新设置该样式的属性,因为user agent stylesheet优先级很低,会被覆盖,这样就不会影响到我们的样式了,比如这里我就讲form 的margin-bottom设为0px。 User Agent ...

    react-native-extended-stylesheet, 用于本机响应的扩展样式表.zip

    react-native-extended-stylesheet, 用于本机响应的扩展样式表 本地扩展样式表 在替换的过程中,使用媒体查询,变量,动态主题,单位,百分比,算术操作,比例和其他样式元素来调整本地样式表。 演示工具安装工具...

    Stylesheet Count-crx插件

    标题中的“Stylesheet Count-crx插件”是指一种专门针对浏览器的扩展程序,其主要功能是统计并显示当前浏览页面中包含的样式表(CSS)数量。这种插件通常适用于前端开发者、网页设计师或者对网页性能有特殊关注的...

    2015-stylesheet

    克隆存储库以获取文件和配置,在终端上输入 git git clone git@github.org:hackathongi/2015-stylesheet.git ,或使用您喜欢的 GIT 工具或 IDE。 或者,如果您必须使用样式表或脚本对前端文件做出贡献,则需要一些...

    jquery-stylesheet:用于样式表操作的jQuery插件

    jQuery StyleSheet jQuery.stylesheet插件允许您动态添加,删除和更改CSS规则。 将更改应用于CSS规则比遍历匹配元素并对每个元素应用相同的更改更为有效,尤其是在元素很多或更改触发多次昂贵的绘制操作的情况下。 ...

    Change Stylesheet in Javascript.zip

    在JavaScript中,改变样式表(Stylesheet)是前端开发中常见的任务,这涉及到动态更新页面的外观和布局。本教程将深入探讨如何在JavaScript中操作CSS样式表,以实现动态效果,尤其关注游戏场景中的应用。 首先,...

    react-native-extended-stylesheet:用于React Native的扩展StyleSheets

    React本机扩展StyleSheet 用媒体查询,变量,动态主题,相对单位,百分比,数学运算,缩放和其他样式化内容直接替换 。 演示版 可以在浏览器或使用此与Extended StyleSheets一起玩。 安装 npm i react-native-...

    Link 标签 rel=Stylesheet的实际作用

    在上述示例中,`<link rel="stylesheet" type="text/css" href="theme.css" />` 这行代码就是在文档头部引入了一个名为 "theme.css" 的外部 CSS 文件,这样,CSS 文件中的样式规则就会应用到整个 HTML 页面,从而...

Global site tag (gtag.js) - Google Analytics