blueprint CSS框架教程

 

joomla 2.5默认配置了一个空白模板atomic,方便用户利用它来创建自己网站模板。比起joomla 1.5,也算是一个贴心的改进。Atomic空白模板是基本blueprint CSS框架来框建的,下面我们就来看一下blueprint CSS框架的官方中文教程。

blueprint CSS框架在github上链接的中文教程在墙外,为方便大家浏览,故转载此教程,并做了一定的文章排版与内容修改。

原教程页面地址:http://chuanliang.wordpress.com/2007/09/14/blueprint-css-framework/ 

blueprint CSS框架的介绍

blueprint是一个所谓的css framework,相比较而言blueprint代码中的注释还是比较详细的。

按照Jeff Croft的Frameworks for Designers(或中文版本理解Web框架,和如何构建一个CSS框架)描述的如何构建一个css framework的方法:

构建一个框架有几种可能的方式,但最常见,可以说是最有用的,抽象通用的CSS放到一个独立样式表文件,该样式表文件只包含整体的一个特有部分。例如,你可以,一个样式处理排版,另一个处理大量重置。这种好的方法能使你选择性引入你需要的样式,在你框架里可能有六七个不同的样式文件,但不需要其中的一两个,只要不引入即可。我们团队创建的框架包含5个样式文件:

  • reset.css —处理重置
  • type.css —处理排版
  • grid.css —处理布局
  • widgets.css —处理小零件(widgets),如tab菜单、下拉菜单、以及“更多”按钮
  • base.css —包含所有的其他样式表文件,以便我们只需要在(X)HTML引用base.css即可使用整个CSS框架

然后,我们把框架存放在一个单独的地方,使每一个站点都引入这个框架。当然,每一个网站也需要有特有样式表,特有样式对框架进行了必要的补充。

blueprint的构建方式:

分而治之:

buleprint在功能组织上,将诸如布局(layout)、排版(typography)、组件(widget)、重置(reset)、打印 (print)等功能分散到不同的css文件中。这样方便使用者只需要导入自己所要使用的功能,不用导入全部文件,提高页面装载性能。目前在组件部分只提供了对button的处理,尚未做到麦肯锡的MECE(”相互独立,完全穷尽”)的道。

统一接口:

尽管功能分散到多个css文件,但是导入时候,仍然只需要包含同样的文件screen.css文件,具体的导入细节在screen.css中再处理,统一了对外接口。

<link rel=”stylesheet” href=”css/blueprint/screen.css” type=”text/css” media=”screen, projection” />

blueprint 所包含的css文件说明:

screen.css

This is the main file of the framework. It imports other CSS files from the “lib” directory, and should be included on every page.

类似于Jeff Croft的base.css功能,只需要包含此文件,就可以导入

print.css

This file sets some default print rules, so that printed versions of your site looks better than they usually would. It should be included on every page.

用于处理打印,可以归类为widget。

lib/grid.css

This file sets up the grid (it’s true). It has a lot of classes you apply to divs to set up any sort of column-based grid.

用于处理页面的布局(栏目)

lib/typography.css

This file sets some default typography. It also has a few methods for some really fancy stuff to do with your text.

用于处理页面元素的排版。

lib/reset.css

This file resets CSS values that browsers tend to set for you.

用于重置页面,对没有指定css属性的页面元素指定缺省值。

lib/buttons.css

Provides some great CSS-only buttons.

用于处理按钮,可以归类为widget

lib/compressed.css

A compressed version of the core files. Use this on every live site. See screen.css for instructions

提供压缩过的(包含grid.css,tyopgraphy.css,reset.css,buttons.css)的css文件。

blueprint CSS框架的使用研究

grid.css研究

对跨浏览器居中处理的兼容性处理

一般而言,要处理firefox、ie在处理居中时候的不同,采用如下方式:

body{
text-align: center;
}

div#container{
margin-left: auto;
margin-right: auto;
width: 50em;
text-align: left;
}

摘自:http://www.maxdesign.com.au/presentation/center/

blueprint的处理方式:

body {
text-align: center; /* IE6 Fix */
margin:36px 0;
}

/* A container should group all your columns. */
.container {
text-align: left;
position: relative;
padding: 0;
margin: 0 auto; /* Centers layout */
width: 1150px; /* Total width */
}
分栏(Columns)的实现

blueprint的处理方式:

blueprint定义了.column , .span-x ,.last ,两者结合来实现分栏功能。

其中:.column定义栏目的float属性;.span-x定义栏目宽度;.last将margin-right置为0px,

.column {
float: left;
margin-right: 10px;
padding: 0;
}

/* Use these classes to set how wide a column should be. */
.span-1 { width: 30px; }
.span-2 { width: 70px; }
.span-3 { width: 110px; }
.span-4 { width: 150px; }
...
.span-8 { width: 310px; }
.span-9 { width: 350px; }
.span-10 { width: 390px; }
...
.span-23 { width: 910px; }
.span-24 { width: 950px; margin: 0; }
.span-25 { width: 200px; }
.span-26 { width: 1150px; margin: 0; }
/* The last element in a multi-column block needs this class. */
.last { margin-right: 0; }
三栏的实现:
<div class="container">
<div class="column span-24">
Header
</div>
<div class="column span-4">
Left sidebar
</div>
<div class="column span-16">
Main content
</div>
<div class="column span-4 last">
Right sidebar
</div>
</div>
四栏的实现:
<div class="container">
<div class="column span-26">
Header
</div>
<div class="column span-4">
Left sidebar
</div>
<div class="column span-3 ">
Main content 0
</div>
<div class="column span-25">
Main content 1
</div>
<div class="column span-4 last">
Right sidebar
</div>
</div>

注意把.container中的width(定义了整个页面的width)修改为1150px

空白栏目的实现:

对于多栏目(例如5栏目),其中有空白栏目(例如左右两栏目为空白),可以使用.append-x和.prepend-x来填充。

其中.append-x在栏目后(padding-right)添加空白栏目,.prepend-x在栏目前(padding-left)添加空白栏目。

通用的容器定义
/* A container should group all your columns. */
.container {
text-align: left;
position: relative;
padding: 0;
margin: 0 auto; /* Centers layout */
width: 1150px; /* Total width */
}

2.2、reset.css研究

reset.css的最初代码应该来自于Eric Meyer,Eric Meyer有两篇关于reset的日志,用于处理跨浏览器缺省值不同的问题。Eric Meyer的文档写得很精彩:

Reset Reasoning:http://meyerweb.com/eric/thoughts/2007/04/18/reset-reasoning/

Reset Reloaded:http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/

为何要reset

The basic reason is that all browsers have presentation defaults, but no browsers have the same defaults. (Okay, no two browser families—most Gecko-based browsers do have the same defaults.)
For example, some browsers indent unordered and ordered lists with left margins, whereas others use left padding. In past years, we tackled these inconsistencies on a case-by-case basis;

为何使用reset style,而不是universal selector

所谓universal selector 就是使用* 来代表document所有的元素,例如

* {
margin: 0;
padding 0;
}
关于reset style话题的一些资源:

YUI的reset库:

http://developer.yahoo.com/yui/reset/

http://leftjustified.net/journal/2004/10/19/global-ws-reset/

以下几篇实际上是讨论css framework或tips的文章,只不过都提到了reset话题。

http://www.smashingmagazine.com/2007/05/10/70-expert-ideas-for-better-css-coding/

http://www.christianmontoya.com/2007/02/01/css-techniques-i-use-all-the-time/

http://businesslogs.com/design_and_usability/my_5_css_tips.php

http://www.pingmag.jp/2006/05/18/5-steps-to-css-heaven/

2.3、typography.css研究

typography.css用于确定页面元素缺省的排版格式(baseline):

Setting Type on the Web to a Baseline Grid:

http://alistapart.com/articles/settingtypeontheweb

2.4、buttons.css研究

Rediscovering the Button Element 讨论了用button元素来替代input元素的种种好处,button元素是提供了较为丰富的功能。

http://particletree.com/features/rediscovering-the-button-element

2.4、print.css研究

Eric Meyer有一篇关于css实现print功能的文章,可以作为理解print.css的参考。

CSS Design: Going to Print

Print Different

2.5、compressed.css

compressed.css是对blueprint几个文件压缩合成包,同时也对css文件进行了压缩,去除了无用的空格、换行、注释等文本。

此种方式用于在上生产系统部署时候使用,避免在页面导入多个css文件,同时也有利于提高页面性能。

按照lib/screen.css中的说明,应该使用了teenage提供的css压缩服务:

http://teenage.cz/acidofil/tools/cssformat.php

另外类似的提供对css、javascript进行优化、压缩的服务还有:

http://csstidy.sourceforge.net/ (开源)

http://www.cssdrive.com/index.php/main/csscompressor/

http://www.cleancss.com/ (基于csstidy)

3、使用例子

4、参考文档

http://code.google.com/p/blueprintcss/wiki/Tutorial

5、相关项目

blueprint-generator: http://kematzy.com/blueprint-generator/

tripoli : http://monc.se/tripoli/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值