看了此二文,其实我感觉后者(Jim Warren)文章更有意义,前者有抬杠嫌疑,:)

My 5 CSS Tips

5 Steps to CSS Heaven

简单总结如下:

1.css 文件结构。我更喜欢这个 css例子,另一个css例子的头有兴许意思,其余毫无价值。

/* Table of Contents:

Typography

Header Layout

Middle Layout

Footer Layout

*/

/* Typography

————————————————————————————— */

/* Header Layout

————————————————————————————— */

/* Middle Layout

————————————————————————————— */

/* Footer Layout

————————————————————————————— */

2. Avoid Default Styles - 清除默认样式。比如链接的蓝色、下划线;body,ul,li 的 margin,padding;ie image 链接默认边为 1px;hx 的 margin 等等

3.Use Your Utility Tags – 我的理解是使用一些小标签,如 small strong em 等,而不都是 span,span 不够语义。

4.Name According To Where It Is, Not What It Looks Like - 根据位置命名 class,id 而不是外观,这是老话题了。当你一开始定义了

可是老板后来对红色深恶痛绝,于是你的页面中,这个 rednews 的家伙显示的是蓝色。

5.Separate the positioning properties from the typographic properties - 把字体设置和位置设置分开。我觉很有必要!一开始,我们一般都在折腾布局,那时根本顾不上颜色和字体大小之类。混杂一起,维护起来很头疼。

6.Isolate single properties that you are likely to reuse a lot -我感觉自己的理解似乎是反的?大家帮忙看看。从例子看来,作者推荐 a,b,#c,.d 这样集中书写大家都用到的样式。但从文章看来似乎正好相反?

7.Learn to exploit the cascading nature of CSS – 善用层叠(继承),比如两个部分大致一样,就写在一起,不同的部分单独再标出。比如

a,b {background:red;}

b {color:#fff}

注:原文多处理解可能有问题,请各位大虾指正。

  • Filed under: Uncategorized