07、内容(Content)

原文
示例

Some parts of content are ready for alpha testing, however, it isn’t ready to be used in production projects.

内容的一些部分已经准备好进行Alpha测试了,但是还没有准备好在生产项目中使用。

媒体对象(Media Object)

The media object allows you to have an image/flash or other fixed width media to the left or right with some content that describes it in the center.

媒体对象允许您在图像/Flash或其他固定宽度的媒介的左侧或右侧添加一些内容,以便将上述内容描述在中间的位置。

  • Status: ready for alpha testing
  • 状态:准备进行Alpha测试

基础类(Base Classes)

Property Description
media Wrapper for the media object
img Child node of the media object. Generally a link, image, or flash wrapper. Will appear to the left of the .bd. Optional region.
bd Main content area for the media object, can contain any other objects. Protected. Required region.
imgExt Child node of the media object. Generally a link, image, or flash wrapper. Will appear to the right of the .bd. Optional region.
属性 描述
media 媒体对象的包裹容器
img 媒体对象的子节点,链接,图像或flash包裹容器。通常在左侧的.bd区域,可选区域。
bd 媒体对象的主要内容区域,可以包含任何其他对象。受保护,必选区域。
imgExt 媒体对象的子节点,链接,图像或flash包裹容器。通常在右侧的.bd区域,可选区域。

HTML

1
2
3
4
5
6
7
8
<div class="media">
<a href="http://twitter.com/stubbornella" class="img">
<img src="http://a3.twimg.com/profile_images/72157651/tattoo_pink_bkg_square_mini.jpg" alt="Stubbornella" />
</a>
<div class="bd">
<a href="http://twitter.com/stubbornella">@Stubbornella</a> <span class="detail">14 miniutes ago</span>
</div>
</div>

数据表格(Data Table)

It can sometimes be convenient to be able to format a data table to align correctly for particular kinds of data (e.g. currency aligns right). Creating new classes for each kind of data can quickly bloat a file because ideally you want to be able to align the data with a class on the table, tr, td, or th, and have the class closest to the data win in case of conflict. This can be done, but it isn’t how CSS automatically works, so to keep file size down, generic classes that support alignment can be used in conjunction with more semantic classes or microformats.

有时需要方便地格式化数据表格,以便正确对齐特定类型的数据(例如货币右侧对齐)。为每种类型的数据创建新类可能会使文件体积迅速膨胀,理想情况下,在表格中的tr,td或th标签上设置类属性,数据自动与其对齐。虽然可以这样做做,但这不是CSS的方式,所以为了使文件体积缩小,支持对齐的通用类可以与多语义类或微格式一起使用。

  • Status: ready for alpha testing

  • 状态:准备进行Alpha测试

基础类(Base Classes)

Property Description
data Div wrapper for the data table
txtL Aligns left, default alignment, can be applied to table, tr, td, or th.
txtR Aligns right, can be applied to table, tr, td, or th.
txtC Aligns center (horizontally), can be applied to table, tr, td, or th.
txtT Aligns top, can be applied to table, tr, td, or th.
txtB Aligns bottom, can be applied to table, tr, td, or th.
txtM Aligns middle (vertically), can be applied to table, tr, td, or th.
属性 描述
data 数据表格的Div包裹容器
txtL 左对齐, 属于默认对齐方式, 可被用于:table, tr, td, 或 th。
txtR 右对齐, 可被用于:table, tr, td, 或 th。
txtC 居中对齐 (水平方向上), 可被用于:table, tr, td, 或 th。
txtT 上对齐, 可被用于:table, tr, td, 或 th。
txtB 底对齐, 可被用于:table, tr, td, 或 th。
txtM 居中对齐 (垂直方向上), 可被用于:table, tr, td, 或 th。

HTML

1
2
3
4
5
6
7
8
9
10
11
12
<div class="data">
<table class="txtC"><!--table alignment set to center -->
<tr class="odd txtL">
<th scope="row" class="txtR">Right aligned</th>
<td>Left aligned</td>
</tr>
<tr class="even">
<th scope="row">center aligned</th>
<td>center aligned</td>
</tr>
</table>
</div>

文件(Files)

  • /css/content.css

06、模块皮肤(Module Skins)

原文

Each of the three module types needs to be skinned differently. Abstracting all the heavy lifting to the mod, complex, and pop classes means that all of the values in the skins are predictable. In fact, I’ll show you how they can be easily calculated.

三种类型模块的皮肤需要不同的设置方法。将所有繁重的工作抽象到mod, complex, 和 pop3个类中,意味着所有皮肤的值都是可以预测的。接下来,我将会为您展示它们是如何通过简单地计算得到的。

扩展模块(Extending mod)

Let’s create a simple grey rounded corner box.

让我们来创建一个简单的灰色圆角盒子。

1
2
3
4
5
6
7
8
9
10
11
12
<div class="mod simple"> 
<b class="top"><b class="tl"></b><b class="tr"></b></b>
<div class="inner">
<div class="hd">
<h3>simple</h3>
</div>
<div class="bd">
<p>Body</p>
</div>
</div>
<b class="bottom"><b class="bl"></b><b class="br"></b></b>
</div>
1
2
3
4
5
6
7
8
9
10
/* ----- simple (extends mod) ----- */
.simple .inner {
border: 1px solid #D7D7D7;
-moz-border-radius: 7px;
-webkit-border-radius: 7px;
border-radius: 7px;
}
.simple b {
*background-image:url(skin/mod/simple_corners.png);
}
  1. We define the border to be one pixel solid gray. Anytime only one border is used it should be placed on inner rather than the module itself (to simplify the skin).
  2. We then tell browsers that the module should have rounded corners.
  3. Internet Explorer 5.5, 6, 7, 8 do not support rounded corners. Line two provides an image backup to generate these corners. The star hack is used so that better browsers that natively support rounded corners do not download the extra image unnecessarily. You may also choose to omit this line and provide a square corner fallback for IE depending on how much market share they have amongst your visitors.
  1. 首先定义一个1像素的实体灰色边框。任何时候如果只有一个边框被使用,那么应该把它放在inner中而不是模块本身(以简化皮肤样式)。
  2. 然后声明模块应该有圆角。
  3. IE 5.5,6,7,8不支持圆角。第二段样式中用图片做降级方案来生成圆角。样式代码中使用星号Hack方法,指示更高版本的支持原生圆角的浏览器不会下载额外的图片。也可以选择省略掉该段代码,IE上显示为一个方形的角落,这取决于使用IE的用户占比。

复杂类(complex)

pop

Todo

05、模块 - 容器对象(Modules - Container Objects)

原文
示例

Modules are based on the Standard Module Format. They provide a simple, predictable way to skin container objects while maintaining accessibility and performance. Contour skins are separate from background skins, headers, and footers. I suggest you name skins in a way that indicates how that skin should be used (semantically). The module skin should not change the display of objects within its open editable zones. Features include:

  • Less than 2K! (structures)
  • Simple to skin
  • One image per module
  • Height and width agnostic
  • Accessibility and performance baked-in
  • Separates semantic markup from presentational fluff

基于标准模块格式的模块,提供了一个简单、可预测的皮肤容器,同时保持可访问性和性能。轮廓皮肤,背景皮肤,页眉和页尾分别独立。建议基于使用来对皮肤进行命名(语义化)。模块皮肤不应该改变其内部对象的显示。支持以下特性:

  • 小于2K(结构上)
  • 定制皮肤简单
  • 每个模块一张图片
  • 高度和宽度无关
  • 不影响可访问性和性能
  • 分离语义与外观

基础类(Base Classes)

Property Description
mod Base class for all container modules. Use mod unless you specifically need one of the other structure objects. Mod is transparent on the inside, corners overlay content, it can therefore be used with any content. Allows infinite height and width as borders are generated via skin objects that define borders on mod and inner.
complex Extends mod. Allows full image borders for cases where the desired look and feel cannot be generated via borders on mod and inner. complex is transparent on the inside, corners overlay content, thus it can be used with any content.
pop Extends mod. Allows transparent outside, such as drop shadows. Use in cases where the module overlays an image, text, or other variable background. pop is transparent on the outside, content overlays background, thus it cannot be used with any content
top A presentational element which wraps the top corners. It is used by complex to display the upper edge of the block. In other block structures it has no height. This empty, non-semantic element should be inserted via a serverside script or JavaScript, the former is preferable.
bottom A presentational element which wraps the bottom corners. It is used by complex to display the lower edge of the block. In other block structures it has no height. This empty, non-semantic element should be inserted via a serverside script or JavaScript, the former is preferable.
tl A presentational element used to display the top left corner of a block, and in complex the left edge of the block. This empty, non-semantic element should be inserted via a serverside script or JavaScript, the former is preferable.
tr A presentational element used to display the top right corner of a block, and in complex the right edge of the block. This empty, non-semantic element should be inserted via a serverside script or JavaScript, the former is preferable.
bl A presentational element used to display the bottom left corner of a block. This empty, non-semantic element should be inserted via a serverside script or JavaScript, the former is preferable.
br A presentational element used to display the bottom right corner of a block. This empty, non-semantic element should be inserted via a serverside script or JavaScript, the former is preferable.
属性 描述
mod 所有容器模块的基类。大多数情况下使用mod即可,除非需要使用其他特定结构对象。Mod背景透明,边角覆盖在内容之上,因此可以和任何内容用在一起。通过在modinner上定义皮肤样式,可以支持长度的高度和宽度。
complex 扩展mod。在无法通过modinner的边框生成所需外观的情况下,允许使用全图像边框。complex背景透明,边角覆盖在内容之上,因此可以和任何内容用在一起。
pop 扩展mod。允许使用透明的外边框,比如投影。在模块包含图像,文本或其他可变背景的情况下使用。pop外边框是透明的,内容覆盖在背景上,因此不能用在任何地方。
top 一个用来包裹顶角的表现元素。使用complex时表现为块的上边缘。在其他的块级元素中,它没有高度。这种空的,没有语义的元素应该由服务端脚本和JavaScript嵌入,推荐前一种方式(笔者按:Server插入或JavaScript插入都不可取,既然需要,简单直接表明)。
bottom 一个用来包裹底角的表现元素。使用complex时表现为块的下边缘。在其他的块级元素中,它没有高度。这种空的,没有语义的元素应该由服务端脚本和JavaScript嵌入,推荐前一种方式(笔者按:Server插入或JavaScript插入都不可取,既然需要,简单直接表明)。
tl 一个用来渲染左上角或complex中左边缘的块级表现元素。这种空的,没有语义的元素应该由服务端脚本和JavaScript嵌入,推荐前一种方式(笔者按:Server插入或JavaScript插入都不可取,既然需要,简单直接表明)。
tr 一个用来渲染右上角或complex中右边缘的块级表现元素。这种空的,没有语义的元素应该由服务端脚本和JavaScript嵌入,推荐前一种方式(笔者按:Server插入或JavaScript插入都不可取,既然需要,简单直接表明)。
bl 一个用来渲染左下角的块级表现元素。这种空的,没有语义的元素应该由服务端脚本和JavaScript嵌入,推荐前一种方式(笔者按:Server插入或JavaScript插入都不可取,既然需要,简单直接表明)。
br 一个用来渲染右下角的块级表现元素。这种空的,没有语义的元素应该由服务端脚本和JavaScript嵌入,推荐前一种方式(笔者按:Server插入或JavaScript插入都不可取,既然需要,简单直接表明)。

标记(The Markup)

模块类(Module)

Mod is the basic container, all other containers inherit from this one. This is the high performance container that should be used unless you specifically need another type.

  • One tiny image
  • Expands to any height or width
  • Compatible with any content
  • Choose for any container object that doesn’t require outside transparency or complex borders.

Mod是基本容器,其他所有的容器都继承自它。这是一种具有高表现性的容器,所以除非您需要另外使用其他的样式,您都应当使用它。

  • 一张小图片
  • 支持任意的宽度和高度
  • 兼容任何内容
  • 适用于不需要外部透明度或复杂边界的容器对象。
1
2
3
4
5
6
7
8
9
<div class="mod"> 
<b class="top"><b class="tl"></b><b class="tr"></b></b>
<div class="inner">
<div class="bd">
<p>Lorem ipsum.</p>
</div>
</div>
<b class="bottom"><b class="bl"></b><b class="br"></b></b>
</div>

复杂类(Complex)

Complex should be used in cases where you require images for borders because borders or drop shadows are too complex to be simulated via borders on mod and/or inner.

  • One image
  • Height and width limited by image size
  • Compatible with any content
  • Choose when you require complex borders which cannot be simulated via css borders on mod and inner.

复杂类(complex)被用在需要图片边框的时候,此时使用mod属性和(或者)inner属性来描述边框和下落的阴影过于复杂,所以推荐使用complx类。

  • 一张图片
  • 高度和宽度受限于图片尺寸
  • 兼容任何内容
  • 当需要使用复杂的边框,并且无法通过mod和inner类下的css边框来实现的时候。

Inspired by a conversation with Arnaud.

这些内容是受到Arnaud的启发产生的想法。

1
2
3
4
5
6
7
8
9
<div class="mod complex"> 
<b class="top"><b class="tl"></b><b class="tr"></b></b>
<div class="inner">
<div class="bd">
<p>Lorem ipsum.</p>
</div>
</div>
<b class="bottom"><b class="bl"></b><b class="br"></b></b>
</div>

弹出类(Popup)

Use for popups and other containers that need outside transparency.

  • One image
  • Height and width limited by image size
  • Compatible with any container, but not any content
  • Choose when you require outside transparency which cannot be simulated. (do i need to make this work with clip rather than bkg position?)

用于需要外部透明度的弹出窗口和其他容器。

  • 一张图片
  • 高度和宽度受限于图片尺寸
  • 兼容任何容器,但不一定兼容任何内容
  • 当需要使用无法模拟的外部透明效果时使用(是否使用clip而不是bkg定位的方式更合适?)

Inspired by Leslie Sommers mojo blocks.

这些内容是受到Leslie Sommers mojo blocks启发产生的想法。

1
2
3
4
5
6
7
8
9
<div class="mod pop"> 
<b class="top"><b class="tl"></b><b class="tr"></b></b>
<div class="inner">
<div class="bd">
<p>Lorem ipsum.</p>
</div>
</div>
<b class="bottom"><b class="bl"></b><b class="br"></b></b>
</div>

皮肤使用建议(Skinning suggestions)

The contour and the background can be used to define the intersection of two parameters. For example you cross product status with product type. E.g. sale, normal, and featured backgrounds with motorcycle, helmet, and clothing contours. In so far as possible, keep your classes as abstract as they can reasonably be. For example choose motorcycle over ducati, ducatiMonster, or NicolesDucatiMonster620dark – unless you really mean to exclude all other uses!

轮廓和背景可以定义成两个类组合使用。例如,当需要联合使用产品状态和产品类型的时候。例如sale, normalfeatured的背景类和motorcycle, helmetclothing的轮廓类组合。保持类尽可能合理的抽象。例如选择使用motorcycle属性而不是ducati, ducatiMonsterNicolesDucatiMonster620dark – 当然,除非您真的不想将它们复用!

Be careful not to choose classes linked to the display of the object (e.g. big blue borders). The client will change their mind, you’ll have classes which no longer correlate to actual display.

当心!不要使用与对象表现形式相关的类名(例如 big,blue,borders)。客户会改变想法,代码中会存在一批与实际表达效果不相符的类。

何时使用模块(How to decide when to use Modules)

Deciding when to use Modules can be confusing. As a rule of thumb, if you are marking up an element on the page that conveys relevant information to the user by itself (e.g. breadcrumbs), you do not need a module. This is a good example for a content object. However, if you are marking up a container that conveys no relevant information on its own (e.g. tabs) and would only make sense to use when you place content objects in it, then you could mark it up as a module.

也许当您使用模块时会感到困惑。从经验上讲,如果您在页面上标记的元素可以向用户传递相关信息时(例如面包屑breadcrumb),您不必使用模块。对于内容对象来说,这是一个很好的例子。但是,如果您在标记一个传递与其本身信息无关的容器时(就像标签tabs)并且只有当您将其中的元素换用内容对象才符合意义时,那您可以将它标注为一个模块。

So you could ask “Is this element conveying any relevant information to the user?”. A container is never useful information to the user on its own; only the content elements within it convey reasonable information to the user. So if your answer to the question is “No”, you could use a module.

所以,您可以这样问:“这个元素是否向用户传递了相关的信息呢?”一个容器本身绝对不会为用户提供有用的信息;只有里面的内容元素可以向用户传递相关的信息。所以,如果您的回答是“No”,那您可能再用一个模块。

Thanks

Great feedback, bug reports,etc. Chris Griego, Jordan LaMons, Arnaud Gueras (as usual), Ryan Grove, Nicholas Zakas, Peter Ellenhauge, Chris Eppstein, Vinod Kerkar, Carsten, Dan H, Cindy Li, etc.

感谢以下人员提供的良好的反馈意见和错误报告等。Chris Griego, Jordan LaMons, Arnaud Gueras (as usual), Ryan Grove, Nicholas Zakas, Peter Ellenhauge, Chris Eppstein, Vinod Kerkar, Carsten, Dan H, Cindy Li等。

04、标准模块格式(Standard Module Format)

原文

The standard module format is based on the YUI module control. I hope to include input from microformats and HTML5 communities to inform the choice of class names.

标准模块格式基于YUI模块控制。我希望从微格式和HTML5社区收集一些意见,来为类选择合适的名称。

Property Description
mod Module is the wrapper for every container object. It provides basic structure for a transparent inside module. It can be extended by mojo or agto provide for transparent outside and complex borders respectively.
inner Inner exists for two reasons. First, it solves a bug (Opera prior to version 8.5) in which position relative and overflow hidden cannot exist on the same element. Second, it allows for two elements on which borders can be placed to extend the number of blocks that can be built without using image based borders.
hd The module header generally contains a heading, but may also contain buttons, links, tabs, etc. hd provides basic structure and can be extended via skin classes. A module can have 0-1 (should this be 0-n?) hd.
bd The body is the main open editable region of the module. It is an obligatory region, the module may contain 1-n bodies.
ft The module footer is an object. ft provides basic structure and it can be extended via skin classes.
属性 描述
mod 模块是容器对象的包装器,为内在模块提供了透明的基本结构。可以使用mojo 或者 ag分别扩展成透明的外边距和复杂的边框。
inner 内元素(inner)存在有两个原因。第一,它解决了一个bug(Opera 8.5之前的版本存在),相对定位和溢出隐藏没办法同时存在于一个元素上。第二,使用两个元素的边框扩展了块的数量,而不需要基于图片的边框。
hd 这个模块头通常包括一个标题,也可以包含按钮,链接,标签等等。hd提供了基本的结构并且可以通过皮肤类来扩展。一个模块中可以包含0-1(或者说0-n?)个hd
bd 主体部分是模块中主要的开放可编辑的区域。它是必须存在的区域,模块可以包含1-n个主体部分。
ft 这个尾部模块是一个对象。ft提供了基本的结构并且可以由皮肤类来扩展。
1
2
3
4
5
6
7
<div class="mod">
<div class="inner">
<div class="hd">head</div>
<div class="bd">body</div>
<div class="ft">foot</div>
</div>
</div>

03、网格(Grids)

原文

Grids are used to break any space into fractions, they can be nested and stacked. A unit can contain another line or it can contain other objects directly. The sum of the fractional sizes of all children of one line should be equal to one. Grids control width, content controls height. The grids have all the functionality of YUI grids and some other important features.

网格用于将行空间等分,这些等分单元可以嵌套和堆叠。一个单元可以继续做行等分,也可以直接包含其他的元素。一行中的所有内容的空间总和应当等于其他一行的空间。网格控制着宽度,内容控制着高度。网格模块包含YUI网格中所有的功能和一些其他重要的特性。

  • Less than 1kb! (including full templates and grids)
  • Infinite nesting and stacking.
  • The only change required to use any of the objects, is to place it in the HTML. No changes to other places in the DOM, and no location dependent styling.
  • Easy integration with back-end development.
  • Easy for beginners to create complex page layouts.
  • 小于1kb!(包含所有的模板和网格)。
  • 可以无限地嵌套和堆叠。
  • 只需将需要的对象放到HTML中。DOM中其他地方不需要改变,也不会影响定位相关样式。
  • 便于后端开发工程师集成。
  • 便于初学者创建复杂页面布局。

Please help me test the grids and template objects. Put them through their paces and let me know if you manage to break them!

请帮我测试网格和模板对象。请您测试它们的效果,有任何疑问,请联系我!

Base Classes

Property Description
line Groups units on one horizontal line. Note: for mobile layout units may be stacked to avoid horizontal scrolling.
unit Base class which divides a line into sections (columns).
sizeXofY Extends unit. Indicates the fractional width of the unit, for example size3of4 would take up three quarters, or 75%, of the horizontal space. The following fractions are supported: 1, 1/2, 1/3, 2/3, 1/4, 3/4, 1/5, 2/5, 3/5, 4/5
lastUnit Extends unit. Applied to the last child of every line.
属性 描述
行(line) 一组网格单元位于一条水平的行上。注意:对于移动端布局单元来说,网格单元可能会垂直堆积以避免水平滚动。
单元(unit) 单元基类,将一行分为几个部分(列)。
sizeXofY 继承自unit。表明单元的占比宽度,例如,size3of4表示占据整个水平空间的四分之三。支持的分数形式如下:1, 1/2, 1/3, 2/3, 1/4, 3/4, 1/5, 2/5, 3/5, 4/5。
最后一个单元(lastUnit) 继承自unit. 应用于每行中最后一个子元素。

Grids possible with OOCSS framework by Stubbornella (aka Nicole), on Flickr

在Flickr上,Stubbornella(又名Nicole)制作的OOCSS框架中网格可能的实现

Grids possible with OOCSS framework

一半(Halves)

1
2
3
4
5
6
7
8
9
10
<div class="line">
<div class="unit size1of2">
<h3>1/2</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of2 lastUnit">
<h3>1/2</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

三等分(Thirds)

1/3, 1/3, 1/3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div class="line">
<div class="unit size1of3">
<h3>1/3</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of3">
<h3>1/3</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of3 lastUnit">
<h3>1/3</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

1/3, 2/3

1
2
3
4
5
6
7
8
9
10
<div class="line">
<div class="unit size1of3">
<h3>1/3</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size2of3 lastUnit">
<h3>2/3</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

四等分(Quarters)

1/4, 1/4, 1/2

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<div class="line">
<div class="unit size1of4">
<h3>1/4</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of4">
<h3>1/4</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of2 lastUnit">
<h3>1/2</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

3/4, 1/4

1
2
3
4
5
6
7
8
9
10
<div class="line">
<div class="unit size3of4">
<h3>3/4</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of4 lastUnit">
<h3>1/4</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

五等分(Fifths)

4/5, 1/5

1
2
3
4
5
6
7
8
9
10
<div class="line">
<div class="unit size4of5">
<h3>4/5</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of5 lastUnit">
<h3>1/5</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

2/5, 3/5

1
2
3
4
5
6
7
8
9
10
<div class="line">
<div class="unit size2of5">
<h3>2/5</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size3of5 lastUnit">
<h3>3/5</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

复杂的集合 - AG测试(Complicated Nesting - the AG test)

AG test of a great grids system by Stubbornella (aka Nicole), on Flickr

在Flickr上,由Stubbornella (aka Nicole)设计的基于大型的网格系统的AG测试

AG test of a great grids system

Many years ago Arnaud Gueras, an excellent developer I worked with, created this litmus of a great grids system. It should be able to nest any combination of the units and lines, and so it should be able to create the complicated layout below. His test reminded me of the golden mean, so I still use it today.

许多年前,和我一起工作的优秀工程师Arnaud Gueras创建一个完美的网格系统。它应当可以实现聚集所有单元和行的结合,并且可以创建一个复杂的布局结构。他的测试为我提供了这个完美的想法,我一直沿用至今。

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<div class="line">
<div class="unit size1of5">
<h3>1/5</h3>
<p>Lorem ipsum dolor sit amet...</p>
<p>Lorem ipsum dolor sit amet...</p>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size3of5">
<!-- line -->
<div class="line">
<div class="unit size1of2">
<h3>1/2</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of2 lastUnit">
<h3>1/2</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>
<!-- /line -->
<div class="line">
<div class="unit size1of3">
<h3>1/3</h3>
<p>Lorem ipsum dolor sit amet...</p>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size2of3 lastUnit">
<!-- line -->
<div class="line">
<div class="unit size1of2">
<h3>1/2</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
<div class="unit size1of2 lastUnit">
<h3>1/2</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>
<!-- /line -->
<div class="line">
<div class="unit size1of1">
<h3>1</h3>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>
</div>
</div>
</div>
<div class="unit size1of5 lastUnit">
<h3>1/5</h3>
<p>Lorem ipsum dolor sit amet...</p>
<p>Lorem ipsum dolor sit amet...</p>
<p>Lorem ipsum dolor sit amet...</p>
</div>
</div>

02、模板(Template)

原文

Templates are used to solve common design patterns for page layout. Using these templates you can build pages which have a header, footer, left and right columns, and a main content area. Any of the sections can be broken up via grids. You can also use grids instead of columns. The main column is fully liquid, taking up all the rest of the space when the left column and right column have been rendered.

模板是用来解决页面布局的通用设计模式。可以使用模板来构建一个包含页眉、页脚、左右边栏和主体内容区域的页面。任何部分都可以通过网格进行布局,也可以使用网格来代替竖栏布局。主体栏是流式布局,当左右边栏渲染完成后,主体栏会充满剩下的全部空间。

Please help me test the grids and template objects. Put them through their paces and let me know if you manage to break them!

请帮我测试网格和模板对象,测试它们的效果,如果出现问题,请联系我!

基础类(Base Classes)

Property Description
page Main wraps site content. It can be extended via the classes oldSchool and liquid to provide 750px and full width layouts respectively.
head Site header, generally contains custom code. (e.g. horizontal navigation, logo, search box)
body Main content area, body of the page.
foot Site footer, generally contains custom code.
main Creates a main content area, often the center column. Fully liquid, it takes all remaining space when left and right columns have been rendered. You may have 1 main columns.
leftCol Creates a left column, default width is 250px. Extended by gMail, gCal, yahoo, and myYahoo to create widths of 160px, 180px, 240px, and 300px respectively. You may have 0-n left columns.
rightCol Creates a right column, default width is 250px. Extended by gMail, gCal, yahoo, and myYahoo to create widths of 160px, 180px, 240px, and 300px respectively. You may have 0-n right columns.
gMail Extends leftCol and rightCol to create a 160px column width.
gCal Extends leftCol and rightCol to create a 180px column width.
yahoo Extends leftCol and rightCol to create a 240px column width.
myYahoo Extends leftCol and rightCol to create a 300px column width.
oldSchool Extends page to create a 750px layout.
liquid Extends page to create a full-width liquid layout.
属性 描述
页面(page) 网站整页。它可以由oldSchoolliquid属性分别扩展为750px和全宽的布局。
页眉(head) 网站头部,通常包含自定义代码组成。(比如由水平导航栏,logo,搜索框)
主体(body) 网站主体内容区域,是页面的主体部分。
页尾(foot) 网页尾部,通常包含自定义代码部分。
主要区域(main) 页面的主要内容区域,经常是中心栏。它全部是流式布局,会填充左右边栏渲染剩下的全部区域。您可以有一个主要的中心栏。
左边栏(leftCol) 左边栏,默认的宽度是250px。可以分别由gMail, gCal, yahoomyYahoo 属性扩展为160px, 180px, 240px, 和 300px。您可以有0个到n个左边栏。
右边栏(rightCol) 右边栏,默认的宽度是250px。可以分别由gMail, gCal, yahoomyYahoo 属性扩展为160px, 180px, 240px, 和 300px。您可以有0个到n个右边栏。
gMail 扩展leftColrightCol为160px的列宽。
gCal 扩展leftColrightCol为180px的列宽。
yahoo 扩展leftColrightCol为240px的列宽。
myYahoo 扩展leftColrightCol为300px的列宽。
oldSchool 扩展page为750px宽的布局。
liquid 扩展leftCol为全宽的流式布局。

基本模板(Basic template)

1
2
3
4
5
6
7
8
9
<div class="page">
<div class="head"><!-- Head --></div>
<div class="body"><!-- Body -->
<div class="leftCol"><!-- Left Column (optional region) --></div>
<div class="rightCol"><!-- Right Column (optional region) --></div>
<div class="main"><!-- Main Content --></div>
</div>
<div class="foot"><!-- Foot --></div>
</div>

全宽模板,两列,gmail格式类型(Full width template, 2 columns, gmail style (160px left column width))

1
2
3
4
5
6
7
8
9
<div class="page liquid">
<div class="head"><!-- Head --></div>
<div class="body"><!-- Body -->
<div class="leftCol gMail"><!-- Left Column (optional region) --></div>
<div class="main"><!-- Main Content --></div>
<!-- note: right column has been removed -->
</div>
<div class="foot"><!-- Foot --></div>
</div>

目标(Goals)

In object oriented CSS the most important goal is to have a single template from which all pages are built. This eases CMS development because by having a single starting point all pages can be made into any other page. Users of the CMS do not have traps in which a page they have built cannot be morphed into a different page type. Another goal of an OO template is to have each section (column, header, etc) control its own destiny. Practically, that means that if you want to add a left column to the template, the only required action should be actually adding the column to the HTML. You never want to write CSS in such a way that changes are required higher in the DOM tree in order to make child elements behave properly. Looping through the DOM is costly for CMS development. Similarly, if you want to have a different left column width, it should be accomplished by extending the left column object by adding an additional class.

在面向对象的CSS中,最重要的目标是创建一个唯一的通用模板,可以用来构建所有页面。这会简化CMS的开发,因为从一个单页模板出发,可以构建成任何需要的页面。CMS用户也不必陷入一个单一页面没法变成不同页面类型的苦恼。面向对象的模板的另一个目标是每个部分(比如列,页头,等等)可以控制自身的变化。特别的是,如果您想向模板中添加一列左边栏,您唯一要做的就是向HTML中添加一列竖列,而不需要对着DOM,编写复杂的CSS样式完成需要的效果。循环整个DOM结构对于CMS的开发是很费事的。相似的,如果需要一个不一样的列宽,唯一需要做的就是给左列对象添加一个额外的类。

扩展一个对象(Extending an object)

1
<div class="leftCol gMail"> ... </div>

制定模板(Customizing the template)

You may not find the default and extended widths of columns or pages match your site. In this case you can extend the column or main objects to allow custom widths. For performance reasons, you should avoid customizing templates whenever possible.

列宽度、页面宽度的默认和扩展可能跟您的站点不匹配,这种情况下可以通过继承列或者主体对象来实现自定义宽度。出于性能考虑,应该尽量避免自定义模板。

列(Columns)

myColumn extends column objects to allow for custom column widths.

myColum继承列对象,实现列宽度的自定义。

1
.myColumn{width:400px;}

主页(Main page)

myPage extends main.

myPage继承main

1
.myPage{width:1050px !important;}

已知的问题(Known Issues)

  • Source order - the right column is before the main content in the source order. This choice was made in order to allow the columns to be completely independent objects and to have one unique template rather than multiple starting points for a site. This speeds and simplifies CMS development and enhances usability for those creating pages within the CMS. Skip to content links and navigational items marked up as lists are strongly encouraged.

  • 源码顺序 - 在源码中,右边栏的顺序应该在主体内容部分之前,目的是为了让边栏成为完全独立的对象,并且对于整个网站,从唯一的模板做起点开始编码,避免从多个不同的起点。这样可以加速和简化CMS的开发,并且提高页面的可用性。同时强烈建议把调转到内容区域的链接列表和导航列表用列表标记实现。

  • Overflow - the containing blocks are made to wrap floats using the contexte de formattage; overflow:hidden; _overflow:visible; zoom:1;. This is known to cause printing bugs in older versions of Firefox and can cause absolutely positioned blocks originating in that container to be cropped. Removing floats and overflow via the print stylesheet is a corrective option.

  • 溢出 - 包含块使用内容格式化的方式包含浮动块;overflow:hidden; _overflow:visible; zoom:1;。在老版本的Firefox中这会造成打印bug,并导致包含在该该块的绝对定位的块级元素被截短。针对这种情况,可以移除浮动和溢出,使用专门的打印样式表代替。

01、面向对象的CSS(Object Oriented CSS)

原文

How do you scale CSS for thousands of pages? Object Oriented CSS is an answer. It’s an approach for writing CSS that’s fast, maintainable, and standards-based. It adds much needed predictability to CSS so that even beginners can participate in writing beautiful websites. Nicole Sullivan first presented it at Web Directions North in Denver and the response has been overwhelming.

如何在大量的页面中重用CSS呢?面向对象的CSS是一个不错的选择。这是一种快速编写可维护、标准化CSS代码的方法。为CSS添加了急需的可预测性,即使初学者也能参与编写完美的网站。尼科尔·沙利文(Nicole Sullivan)在丹佛的“Web Directions North”会议上首次提出,获得了很大反响。

This Github project is for the OOCSS framework—a collection of code that’s built using the OOCSS approach and is meant to help you get started. However, the framework is not the same thing as the OOCSS idea. (Confusingly though, they have the same name…that’ll probably change.)

这个Github项目就是一个OOCSS框架——使用OOCSS方法构建起来的代码集合,旨在帮助您起步使用。但是,这个框架和OOCSS的思想是两码事(它们只是名字相同而已…以后也许会改变一下)。

什么是CSS对象?(What’s a CSS Object?)

Basically, a CSS “object” is a repeating visual pattern, that can be abstracted into an independent snippet of HTML, CSS, and possibly JavaScript. That object can then be reused throughout a site.

根本上说,CSS “对象”是一种可复用的可视化模式,可以被抽象为独立的HTML,CSS和必要的JavaScript片段。然后可以在整站中重用该对象。

For instance, in the OOCSS framework the media object describes a content block containing a fixed-size media element (e.g. image or video) along with other variable-size content (e.g. text). Another example is the module object, which describes a generic content block with a required body area and optional header and footer areas.

例如,在OOCSS框架中,媒体对象用来表示内容容器,包含固定大小的媒体元素(例如图像或视频)和其他可变大小的内容(例如文本)。另一个例子是模块对象,它用来表示通用的内容块,包含必需的主体部分和可选的页眉、页尾区域。

想要了解更多有关对象的内容,请参见FAQ页面…

OOCSS的两个主要原则(Two Main Principles of OOCSS)

  • 分离结构和外观(Separate structure and skin )

This means to define repeating visual features (like background and border styles) as separate “skins” that you can mix-and-match with your various objects to achieve a large amount of visual variety without much code. See the module object and its skins.

这意味着需要将重复的视觉特征(如背景和边框样式)定义为单独的“皮肤”,与各种对象进行混合和匹配,用少量的代码得到广泛的使用。请参阅模块对象模块皮肤

Separating structure and skin can also mean using classes to name your objects and their components, rather than relying solely on the semantics of HTML. For example, the media object is named with class="media", and its components are named with class="img" (for the image/video component) and class="bd" (for the body/text component).

分离结构和外观意味着使用类命名对象及其组件,而不是仅依赖于HTML的语义。例如,媒体对象以 class="media" 命名,其组件以class="img"(对于图像/视频组件)和class="bd"(用于主体body/文本组件)命名。

By referencing these classes in your stylesheets (say, rather than directly styling the <img> element), your HTML can be flexible. For instance, if a new media element were to take off in the next few years (e.g. <svg>), it could be integrated into the HTML without having to touch the CSS.

通过在样式表中引用这些类(比如说,相对于直接使用<img>元素这样的样式),你的HTML将会更加灵活。例如,如果一个新的媒体元素在未来几年内将会大量使用(比如<svg>),通过这种方式,您可以在不接触CSS的情况下将它融入到HTML中。

  • 分离容器和内容(Separate container and content)

Essentially, this means “rarely use location-dependent styles”. An object should look the same no matter where you put it. So instead of styling a specific <h2> with .myObject h2 {...}, create and apply a class that describes the <h2> in question, like <h2 class="category">.

本质上,这意味着“杜绝使用位置依赖的样式风格”。无论将一个元素放在哪里,对象的表现形式都应该是一样的。所以,不同于对<h2>添加诸如.myObject h2 {...}这样的特殊样式,应该用同一个类诸如<h2 class="category">来描述<h2>

This gives you the assurance that: (1) all unclassed <h2>s will look the same; (2) all elements with the category class (called a mixin) will look the same; and 3) you won’t need to create an override style for the case when you actually do want .myObject h2 to look like the normal <h2>.

这样就可以向您保证:(1)所有没有类属性的<h2>看起来都一样;(2)所有具有某个类别类的元素(称为mixin)看起来都一样;(3)当需要.myObject h2和普通的<h2>看起来一样时,不需要再创建一个覆盖样式。

入门(Getting Started)

  1. Download all the files and set up a local directory.
  2. Open template.html (this is the basic template you will modify to create all other pages).
  3. Set your left and right column widths by extending the column objects
  4. Use grids to break the page up further into smaller sections.
  5. Test site functionality by adding content objects from the content.css file. (These can also be found in library.html).
  1. 下载所有文件并设置本地目录。
  2. 打开template.html(这是您将修改创建所有其他页面的基本模板)。
  3. 通过扩展列对象来设置左右列宽。
  4. 使用网格将页面进一步分割成较小的部分。
  5. 通过从content.css文件添加内容对象来测试站点功能。(这些也可以在library.html中找到)。

准备进行Alpha测试(Ready for alpha testing)

Please help me test the talk bubble objects! Put them through their paces and let me know if you manage to break them. Add feature requests under the “issues” tab.

请帮我测试谈话泡泡对象!通过观察他们,当如果您试图去刺破它,请让我知道。在“问题”选项卡下添加功能请求。

  • Tabs (very experimental)
  • Talk Bubbles
  • Content Objects (particularly media)
  • 标签(很有实践用处)
  • 谈话泡
  • 内容对象(尤其是媒体对象)

稳定性(Stable)

  • Module
  • Template
  • Grids
  • 模块
  • 模板
  • 网格

基础库(Base Libraries)

OOCSS is built on top of reset and fonts from the YUI libraries. These libraries provide a common starting point across different navigators.

OOCSS的基础是建立在YUI库的重置库(reset)和字体(font)之上的。这些库磨平了浏览器之间的差异,提供了一个同样的起点。

  • Reset and Fonts from YUI are a starting point.

  • 以YUI中重置库(Reset)和字体库(Fonts)为起点。

未来(Upcoming)

  • Content objects
  • DHTML blocks (tabs, carousel, toggle, etc)

  • 内容对象

  • DHTML块(标签,轮播,切换等)

感谢!(Thanks!)

I’ve had the good fortune to work/study/play with some amazing developers, engineers, managers, designers, and visionaries over the years. All of them contributed in different ways to shaping my ideas about how CSS should be built and maintained.

多年来,我一直有幸与一些杰出的开发人员,工程师,项目管理人员,设计师和一些有远见的人一起工作/学习/娱乐。他们都在以不同的方式帮助我实现更好的构建和维护CSS的理想。

Many many thanks to Arnaud Gueras, Florian Harmel, Sebastian Tiphaine, Yann Doussot, Thomas Vial, Adrien Thery, Sebastien Cardif, Thomas Vergnaud, Etienne Bernard, Yannick Bonnieux, Renaud Boyerand, Matt Sweeney, Nate Koechley, Leslie Jensen-Inman, Philip Tellis, Stoyan Stefanov, Robin Garner, Kevin Michel, Christophe Dubois, Orphelie Dudemaine, Medhi El Azmi, Christophe Charles, Eric Prudhommeaux, Mark Mason, Tenni Theurer, Steve Souders, Jennifer Le Hegaret, Praveen P N, Doug Crockford, Nicholas Zakas, Mark Norman Francis, Christian Heilmann, Jenny Han Donnelly, Tom Croucher, Brian Rountree, Ryan Grove, Philippe Mihelic, Stephanie Troeth, Nick Fogler, Gonzalo Cordero and the other Jukus, and Dan Cederholm and his book bulletproof.

十分感谢以下所有人员:Arnaud Gueras, Florian Harmel, Sebastian Tiphaine, Yann Doussot, Thomas Vial, Adrien Thery, Sebastien Cardif, Thomas Vergnaud, Etienne Bernard, Yannick Bonnieux, Renaud Boyerand, Matt Sweeney, Nate Koechley, Leslie Jensen-Inman, Philip Tellis, Stoyan Stefanov, Robin Garner, Kevin Michel, Christophe Dubois, Orphelie Dudemaine, Medhi El Azmi, Christophe Charles, Eric Prudhommeaux, Mark Mason, Tenni Theurer, Steve Souders, Jennifer Le Hegaret, Praveen P N, Doug Crockford, Nicholas Zakas, Mark Norman Francis, Christian Heilmann, Jenny Han Donnelly, Tom Croucher, Brian Rountree, Ryan Grove, Philippe Mihelic, Stephanie Troeth, Nick Fogler, Gonzalo Cordero and the other Jukus, and Dan Cederholm和他的防弹书。

I’m sure I’ve forgotten some… deepest apologies.

我很确定我遗忘了一些人….对此感到深深地抱歉。

“If you can’t be a good example, then you’ll just have to serve as a horrible warning.”
—— Catherine Aird

“如果你不能成为一个好榜样,那么你只能作为一个可怕的警告。”
—— 凯瑟琳艾尔德

00、模块化CSS理论——OOCSS目录

OOCSS(Object-Oriented CSS,GithubFAQ),面向对象的CSS,典型案例是BootStrap,toggle组件的示例如下:

1
2
3
4
5
6
7
<div class="toggle simple">
<div class="toggle-control open">
<h1 class="toggle-title">Title 1</h1>
</div>
<div class="toggle-details open">...</div>
...
</div>

主要原则有以下两个:

  1. 分离结构和外观:意味着将视觉特性定义为可复用的单元,如上例中toggletoggle-controltoggle-titletoggle-detail4个类是结构类,simple是外观类。
  2. 分离容器和内容:指的是不再将元素位置作为样式的限定词,如上例中toggletoggle-controltoggle-titletoggle-detail4个类。

资料翻译列表

  1. 面向对象的CSS(Object Oriented CSS)
  2. 模板(Template)
  3. 网格(grids)
  4. 标准模块格式(Standard Module Format)
  5. 模块(Modules)
  6. 模块的表现形式(Module Skins)
  7. 内容(Content)
  8. 按钮(Buttons)
  9. 谈话框(Talk Bubbles)
  10. 滚动栏(Carousel)
  11. UML
  12. 分级浏览器支持(Graded Browser Support)
  13. 常见问题(FAQ)