灌水青年..

blueprint--css framework研究

上一篇 / 下一篇  2007-10-23 10:32:56

介绍

PHPChina 开源社区门户i5i"~5N?n6d9RA

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

|z/j`g0PHPChina 开源社区门户-VO6|V+WZ v6v

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

,ktAv~1m `0PHPChina 开源社区门户 GiK%c-zc

   There are several possible ways to go about building a framework, but the most common and arguably the most useful is to abstract your common CSS into individual stylesheets that each cover a particular part of the whole. For example, you may have a stylesheet that sets up the typography and another that handles the mass reset. The beauty of the approach is the ability to selectively include only the styles that you need. You may end up with six or seven different stylesheets in your framework, but if a particular project doesn’t need one or two of them, they don’t have to be included. The framework we created in our office has five stylesheets:.PHPChina 开源社区门户s,\ xz0xI,t;r

  • reset.css—handles the mass reset.
  • type.css—handles the typography.
  • grid.css—handles the layout grid.
  • widgets.css—handles widgets like tabs, drop-down menus, and “read more” buttons.
  • base.css—includes all the other stylesheets, so that we only need to call base.css from our (X)HTML documents to use the entire framework.
PHPChina 开源社区门户rT{,\Wr

 

c g4c@!}i|0PHPChina 开源社区门户k_y5} b

blueprint的构建方式也与此类似:

c7e F:v o\2z0

W|R"^ f(uXEy0   分而治之PHPChina 开源社区门户t-dL8j0C"v

PHPChina 开源社区门户xrGptC rx2j

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

Ib}?J?l_ L8aan0   统一接口:PHPChina 开源社区门户a-A.S8PtV

PHPChina 开源社区门户-jQ4`/u X j,M

           尽管功能分散到多个css文件,但是导入时候,仍然只需要包含同样的文件screen.css文件,具体的导入细节在screen.css中再处理,统一了对外接口。PHPChina 开源社区门户'x:Nb\.I!K M

X)Y4F*lm!J#q6a*c+e0    <link rel="stylesheet" href="css/blueprint/screen.css" type="text/css" media="screen, projection" />

&JU|4^` T:d J0PHPChina 开源社区门户.jw!bpWQ+J+y1lB

   blueprint 所包含的css文件说明:PHPChina 开源社区门户a"@#x2ObhzW M'``

  • screen.css
    ~2^){!}lh/`l:WBi0  This is the main file of the framework. It imports other CSSPHPChina 开源社区门户lyH3P!GS,C T;Z
      files from the "lib" directory, and should be included onPHPChina 开源社区门户+F WR,Cz
      every page.

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

4Ch.cp)d8a5fzo0
  • print.css
    XBI'BC2Yw0  This file sets some default print rules, so that printed versionsPHPChina 开源社区门户 Tw5[*t? LT:r
      of your site looks better than they usually would. It should be
    z$N#H+IY*K0  included on every page.
PHPChina 开源社区门户 z @T ZP]2IU E] E(C-v

         用于处理打印,可以归类为widget。PHPChina 开源社区门户:iIJrT\7U

  • lib/grid.css
    uT6^;oO9B:t)VB6N0  This file sets up the grid (it's true). It has a lot of classesPHPChina 开源社区门户v)R6d'@"s%i#? Qs
      you apply to divs to set up any sort of column-based grid.
PHPChina 开源社区门户G%I$g.F+h

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

+Ep#~t7[-m*a0
  • lib/typography.cssPHPChina 开源社区门户%DN'mm ^4b
      This file sets some default typography. It also has a few
    )C$Y&}\GX3D*D0  methods for some really fancy stuff to do with your text.
PHPChina 开源社区门户+_&JDw_

          用于处理页面元素的排版。PHPChina 开源社区门户%s4c;Je6y[

  • lib/reset.cssPHPChina 开源社区门户?mt ?,o
      This file resets CSS values that browsers tend to set for you.
PHPChina 开源社区门户4[5V-vR*a Y%z

           用于重置页面,对没有指定css属性的页面元素指定缺省值。PHPChina 开源社区门户TxkfQd/LeY

  • lib/buttons.cssPHPChina 开源社区门户%~3r+vxW5u;Kt
      Provides some great CSS-only buttons.
PHPChina 开源社区门户.|J%V`5Dv

           用于处理按钮,可以归类为widgetPHPChina 开源社区门户RS!DJ(?8o%z%t

  • lib/compressed.cssPHPChina 开源社区门户|)~b~ ^Q.o8d`
      A compressed version of the core files. Use this on every live site.PHPChina 开源社区门户;ye#a't*lLS;g,N
      See screen.css for instructions
PHPChina 开源社区门户:]{\*w;U%e`"vp)d%x

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

Halw"yz0

2、各模块用法研究

2.1、grid.css研究

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

|I@w5t4xg,r0一般而言,要处理firefox、ie在处理居中时候的不同,采用如下方式:PHPChina 开源社区门户{!Qn8G+`0A P%Wf

bodyPHPChina 开源社区门户9H4zVEYm~f^'WT
{
L Z;GFd!af3O3dKA0text-align: center;
)r1fsa*W\s0}
@"z t \kEb0
D|*W:ludo)tdu0div#container
:v9s%bA,Y0{
4O2c9y9y0\ROI5Q,p.f^*b0margin-left: auto;
,OqY-s%G0margin-right: auto;PHPChina 开源社区门户!^+fbI v:oy
width: 50em;PHPChina 开源社区门户:M G({&v4B.|8~
text-align: left;PHPChina 开源社区门户4{4\}k8AR$E)If
}

lA w3Y A `q;|K0          摘自:http://www.maxdesign.com.au/presentation/center/

$e2GYz ED!gy5g}.h$B0

k4Wf ?s&|4Y;`:S0blueprint的处理方式:

e [0o't:[GC;g kr0
body {
tRe%rvc Z)e0text-align: center;/* IE6 Fix */
}4@O%u2h+w0margin:36px 0;
X*|9x1{'N(un0}PHPChina 开源社区门户!j,b8R'S0xp

xT'p6g,tT0/* A container should group all your columns. */
$kW_[8[3BF:x;P0.container {PHPChina 开源社区门户]3H6r;ke.NG
text-align: left;PHPChina 开源社区门户i3e R U,ekGc
position: relative;
4b8Zy x}bua$~0`0padding: 0;
+T7F.|)Nwz+C0margin: 0 auto;/* Centers layout */
5D uQ5J"X(r0width: 1150px;/* Total width */
!yc,y7H*{/P/L0}
  • 分栏(Columns)的实现
PHPChina 开源社区门户?-y6B0}o+^B;T

      blueprint的处理方式:PHPChina 开源社区门户0^1B:]3z-_*h

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

Y,d9s)Q&eI2\0PHPChina 开源社区门户 q3Hpo2M2Vx

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

"S uj.~;^4?(Z0
.column {PHPChina 开源社区门户1Ve,f4v s6U
float: left;
:rzQ3e*b+Me0margin-right: 10px;
%L:{i*r0fvv,x0padding: 0;PHPChina 开源社区门户B{zk+E1L:i?#[
}PHPChina 开源社区门户9gEZJ$I {6h-M(]7U
PHPChina 开源社区门户'L_1zO%llKW
/* Use these classes to set how wide a column should be. */
M;z6o6K@Z h m l0.span-1 { width: 30px; }
7i9q2j)K$h(^G0.span-2 { width: 70px; }PHPChina 开源社区门户NZ S7hh
.span-3 { width: 110px; }
?:`Q[xd0.span-4 { width: 150px; }PHPChina 开源社区门户!|"pOS7y
...PHPChina 开源社区门户6Q+dU)y9j it
.span-8 { width: 310px; }PHPChina 开源社区门户}Er^l j |
.span-9 { width: 350px; }PHPChina 开源社区门户@ t.k5^R4`&}a
.span-10 { width: 390px; }
m]$|SObF \0...
~"~,rlp^0.span-23 { width: 910px; }
gU!P3m5d#|uM"v.[j \0.span-24 { width: 950px; margin: 0; }PHPChina 开源社区门户^(@'jg.T/E?[~
.span-25 { width: 200px; }PHPChina 开源社区门户C0F-e@Lp~
.span-26 { width: 1150px; margin: 0; }PHPChina 开源社区门户Q%FquN*o1OI/`V
/* The last element in a multi-column block needs this class. */
}|(^%K1K\M(z0.last { margin-right: 0; }
 
三栏的实现:
<divclass="container">
h;Y4N*f,kF0<divclass="column span-24">
!P(f%Zc|0HeaderPHPChina 开源社区门户2O)S1Z5DMhZa
</div>
,`6t/b:eq6Fo0<divclass="column span-4">
1VM8Db6^ XG6zv0Left sidebar
a,_$R x.I/P R0</div>PHPChina 开源社区门户/i)T5x1RP_
<divclass="column span-16">PHPChina 开源社区门户'j7fB0Og ~&Kl#r
Main contentPHPChina 开源社区门户3h$R0I3T#re O&D}
</div>
)e-{W L+P&C0<divclass="column span-4 last">PHPChina 开源社区门户 dH {r$E8ay|]P
Right sidebar
8~\ _@UN7a b0</div>PHPChina 开源社区门户4WNg0|I:p?-](T3q/u
</div>
四栏的实现:
<divclass="container">PHPChina 开源社区门户\7r6g1?v])DLS3{X
<divclass="column span-26">
Y S` O7`mxG;u0Header
&q+la)megn+q0</div>
CL/_"r}i0<divclass="column span-4">
*mW2yO2lc B Iu5{0Left sidebar
@Y1SPE$o f0</div>PHPChina 开源社区门户N+m%Ct'Ggz
<divclass="column span-3 ">
%k^)i)Z6SL!U-V0Main content 0PHPChina 开源社区门户nw7p9X#]2@ t
</div>
!?]"]M tr*G/|0<divclass="column span-25">PHPChina 开源社区门户0RSq:gT3Vn
Main content 1PHPChina 开源社区门户_H*flz.M
</div>
JKg+QT0<divclass="column span-4 last">PHPChina 开源社区门户vRr~%]
Right sidebarPHPChina 开源社区门户4j?*rPcq"M-V
</div>
M2nT#C\p0</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. */
UuS m,Uh l(m;_l0.container {
X+rBiP nfH0text-align: left;
%?IIZ t0position: relative;PHPChina 开源社区门户R)F5]1r OE
padding: 0;
;Ia-`z"~0margin: 0 auto;/* Centers layout */
)T&gl ~Im0width: 1150px;/* Total width */PHPChina 开源社区门户x}#e0G `i([1mv'S+W
}
 

2.2、reset.css研究

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

f r)BH#]+?L{0PHPChina 开源社区门户pp0i'T:_iEm6G

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

+z }X*l6aqa)Gn0PHPChina 开源社区门户]K*P_;Pq[H

Reset Reloaded:http://meyerweb.com/eric/thoughts/2007/05/01/reset-reloaded/PHPChina 开源社区门户8aUV4J3],n2H1X#|

  • 为何要reset
PHPChina 开源社区门户IfN-G8^g:T!y

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.)
)?_"w9Ga0For 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;

k d@eF,C%XP0
  • 为何使用reset style,而不是universal selector

!d}u c L|t*@L L0所谓universal selector 就是使用* 来代表document所有的元素,例如PHPChina 开源社区门户)CE*E}+\-bm#dr

* {
:X+w!rG*p.KYB7d0margin: 0;
Y"D"F%g-~S*Pp0padding 0;PHPChina 开源社区门户[9z6N\4\`
}
 
 
  • 关于reset style话题的一些资源:

.U3GB XC&B5{zs0YUI的reset库:http://developer.yahoo.com/yui/reset/PHPChina 开源社区门户5T F-S1B8nY0CJ

PHPChina 开源社区门户!DV:u5e2{ K|8}"Q

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

1mzY uxz2S0

h!V}:_5iD6N0 

\#dqGK0

A5_z-t7N a:p%n0以下几篇实际上是讨论css framework或tips的文章,只不过都提到了reset话题。PHPChina 开源社区门户H"|$K.aAx%N}/_ PL

k.k%f.]%| [0http://www.smashingmagazine.com/2007/05/10/70-expert-ideas-for-better-css-coding/

Nk8^'c#]GymT0

1G JuG([%^Q~0http://www.christianmontoya.com/2007/02/01/css-techniques-i-use-all-the-time/PHPChina 开源社区门户1Qm(fF?+P0@.mX+sX

PHPChina 开源社区门户%{Ov@P&k_7b

http://businesslogs.com/design_and_usability/my_5_css_tips.phpPHPChina 开源社区门户2k jE*n`-HswY:T

fH9Z8k:Qe&K{0a0http://www.pingmag.jp/2006/05/18/5-steps-to-css-heaven/PHPChina 开源社区门户AOrW1e]mW d

-PH)W?3t"bpG0 PHPChina 开源社区门户cC3G k!C~}+}rg

2.3、typography.css研究

PHPChina 开源社区门户4`)v!bWj+[B6_

typography.css用于确定页面元素缺省的排版格式(baseline):PHPChina 开源社区门户$a.l#{\ZpE5RK2u

QsENUg0Setting Type on the Web to a Baseline Grid:

_u6vz X&P sY$i0PHPChina 开源社区门户2GU@'I"m

 http://alistapart.com/articles/settingtypeonthewebPHPChina 开源社区门户!q)G1h)H2@O:F1B-Z

PHPChina 开源社区门户A4M$|0m#Q.ZS"e

 PHPChina 开源社区门户-Mg k2z9o ]

2.4、buttons.css研究

PHPChina 开源社区门户3VM!ln4^o8~

Rediscovering the Button Element讨论了用button元素来替代input元素的种种好处,button元素是提供了较为丰富的功能。PHPChina 开源社区门户P8As8dC

EK}%po4{D'h0http://particletree.com/features/rediscovering-the-button-elementPHPChina 开源社区门户 q~ov9N d7bm7A

PHPChina 开源社区门户5j1|1{"R3F` s f/_

 

h B$^yR?(p0

2.4、print.css研究

PHPChina 开源社区门户u~uPo;DAc LC

Eric Meyer有一篇关于css实现print功能的文章,可以作为理解print.css的参考。PHPChina 开源社区门户r*u;| kMeTM&v

CSS Design: Going to Print

Print Different

2.5、compressed.css

PHPChina 开源社区门户sG%HFh `.j

       compressed.css是对blueprint几个文件压缩合成包,同时也对css文件进行了压缩,去除了无用的空格、换行、注释等文本。PHPChina 开源社区门户/a!?3]zh(^,]Ic

PHPChina 开源社区门户NB)da#Z-A.\O(v

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

-ynx5[y S0

^DW!\ [|5J8s0按照lib/screen.css中的说明,应该使用了teenage提供的css压缩服务:PHPChina 开源社区门户+v@lIV(X,U @2E

J:_.~i0D0 http://teenage.cz/acidofil/tools/cssformat.php

2TkBO}9V0PHPChina 开源社区门户/f.q K1i1qw'|JpD

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

8FTp,z$i R7W0PHPChina 开源社区门户/v ~2n \-k

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

K/d-\ ?8A3Ne/C0

3o"i6j,O8\}hS3D7p0http://www.cssdrive.com/index.php/main/csscompressor/

qE:?`ava-~ }9L0PHPChina 开源社区门户c/]!?i(_"{rfT

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

0B vY,f;J(e#U0

ES$KL:g0V0 

&n0v+ulaqN+\iO0

3、使用例子

^[V`Jh#py0 

(Ux]'|)SPR0PHPChina 开源社区门户5J5SJX"b C4C

 PHPChina 开源社区门户#QrYy,W ~

4、参考文档

http://code.google.com/p/blueprintcss/wiki/TutorialPHPChina 开源社区门户V9UiHEpk7W w9X I

({3Qx^7u)hr'I0 PHPChina 开源社区门户%Tq3nT2P?5`Q j+G

5、相关项目

PHPChina 开源社区门户+@C%Bd-XV?L

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

}$U&u:qY i-F0PHPChina 开源社区门户7ZMZ(e._%\+|

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

6P ]V4r%^4I0P0h0

qK"e({1^l4Ua.C0PHPChina 开源社区门户?@4IZ h
PHPChina 开源社区门户 J5wnU T


TAG: css framework blueprint 框架 compressor csstidy 藏經閣

 

评分:0

我来说两句

显示全部

:loveliness: :handshake :victory: :funk: :time: :kiss: :call: :hug: :lol :'( :Q :L ;P :$ :P :o :@ :D :( :)

数据统计

  • 访问量: 19080
  • 日志数: 102
  • 图片数: 3
  • 书签数: 15
  • 建立时间: 2007-05-19
  • 更新时间: 2007-11-22

RSS订阅

Open Toolbar