使用960网格系统(960 Grid System)设计网页

<!-- Feedsky FEED发布代码开始 --> 如果您喜欢这些文章,欢迎点击此处订阅本Blog <!-- FEED自动发现标记开始 --> <link title="RSS 2.0" type="application/rss+xml" href="http://feed.feedsky.com/softwave" rel="alternate"> <!-- FEED自动发现标记结束 --> Blog 订阅

<!--Google 468*60横幅广告开始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; google_ad_width = 468; google_ad_height = 60; google_ad_format = "468x60_as"; google_ad_type = "image"; //2007-07-26: CSDN google_ad_channel = "6063905817"; google_color_border = "6699CC"; google_color_bg = "E6E6E6"; google_color_link = "FFFFFF"; google_color_text = "333333"; google_color_url = "AECCEB"; google_ui_features = "rc:6"; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--Google 468*60横幅广告结束-->

CSS框架已经出现很长时间了,关于这些框架的用处也被我们讨论了很多遍了。有人说,CSS框架不够先进,还有人说这些框架大大的节省了他们的开发时间。在此,我们将不再讨论这个问题。

前段时间,我了解到了CSS框架。经过对Malo、BluePrint和960做了实验对比后,我得出一个结论:我最喜欢960CSS框架。

本教程将解释这个框架的基本原理,这样你就可以用960来快速进入开发。(注:960网格系统官方网站点击进入

基本原理

你必须知道一些基本原理来“学习这个框架是如何工作的”。你可以通过实验(或者是用firebug)来学习它,不过我也将会在这里为你介绍它。让我们开始吧。

不要编辑960.css文件

首先是一个小提示:不要编辑960.css文件,否则,将来你将不能更新这个框架。因为尽管我们需要布局我们的HTML,我们将创建一个独立的CSS文件。

加载网格

因为我们可以使用一个外部文件的CSS代码,我们必须在我们的HTML网站中加载它们,我们可以通过以下代码来实现:

  1. <linkrel=”stylesheet”type=”text/css”media=”all”href=”path/to/960/reset.css”/>

  2. <linkrel=”stylesheet”type=”text/css”media=”all”href=”path/to/960/960.css”/>

  3. <linkrel=”stylesheet”type=”text/css”media=”all”href=”path/to/960/text.css”/>

这些做好了之后,我们必须添加我们自己的CSS文件。例如,你可以叫这个文件为 style.csssite.css或者其它任何名字。用下面代码引用这个文件:
  1. <linkrel=”stylesheet”type=”text/css”media=”all”href=”path/to/style.css”/>

容器

在960框架中,你可以选择名为.container_12.container_16的两个容器class。他们都是960px的宽度(这就是为什么叫960),它们的不同是分的列数不同。.container_12被分割为12列,.container_16被分割为16列。这些960px宽的容器是水平居中的。

网格/列

有很多列宽可供选择,而且在这两个容器里,这些宽度也不相同。你可以通过打开960.css文件来查看这些宽度。但是这对于设计一个网站来说是不必要的。有一个小技巧可以让这个框架更加易用。

比如,你想要在你的容器里建两列(叫sidebar/content)。你可以这样做:

  1. <divclass="container_12">
  2. <divclass="grid_4">sidebar</div>
  3. <divclass="grid_8">maincontent</div>
  4. </div>

可以看到,你的第一列(grid_4)的数字加上第二列(grid_8)的数字正好是12。也就是说,你不必知道每一列的宽度,你可以选择列宽通过一些简单的数学计算。

如果我们要建一个4列的布局,代码可以是这样的:

  1. <divclass="container_12">
  2. <divclass="grid_2">sidebar</div>
  3. <divclass="grid_6">maincontent</div>
  4. <divclass="grid_2">photo’s</div>
  5. <divclass="grid_2">advertisement</div>
  6. </div>

正如你所看到的那样,这个系统依然很完美。但是如果你想使用嵌套的列的话,你会发现它是有问题的。比如,如果后面三列都属于content列:

  1. <divclass="container_12">
  2. <divclass="grid_2">sidebar</div>
  3. <divclass="grid_10">
  4. <divclass="grid_6">maincontent</div>
  5. <divclass="grid_2">photo’s</div>
  6. <divclass="grid_2">advertisement</div>
  7. </div>
  8. </div>

你会发现这错位了,不过不用着急,这正是我们下一节要说的。

间距

默认情况下,每列之间都有间距。每一个grid_(这里代表数字)class左右都有10个像素的间距。也就是说,两列之间,总共有20px的间距。

20px间距对创建一个有足够宽的空白间距的布局来说是很棒的,它可以让一切看起来很自然。这也是我喜欢使用960的原因之一。

在上面的例子中,我们遇到了个问题,现在我们就来解决它。

问题是,每一列都有左右边距。而嵌套的三列中,第一列和最后一列是不需要边距的,解决方法是:

  1. <divclass="container_12">
  2. <divclass="grid_2">sidebar</div>
  3. <divclass="grid_10">
  4. <divclass="grid_6alpha">maincontent</div>
  5. <divclass="grid_2">photo’s</div>
  6. <divclass="grid_2omega">advertisement</div>
  7. </div>
  8. </div>

我们可以简单的添加”alpha“样式来去掉左边的间距,添加“omega”样式来去除右边的间距。这样我们刚刚创建的这个例子在任何浏览器里面就很完美了(当然包括IE6)。

样式

好了,你现在已经完全了解如果用960框架来创建一个网格布局的基本原理了。当然,我们也可以添加一些样式到我们的布局中。

  1. <divclass="container_12">
  2. <divid="sidebar"class="grid_2">sidebar</div>
  3. <divid="content"class="grid_10">
  4. <divid="main_content"class="grid_6alpha">maincontent</div>
  5. <divid="photo"class="grid_2">photo’s</div>
  6. <divid="advertise"class="grid_2omega">advertisement</div>
  7. </div>
  8. </div>

因为CSS使用特性来确定哪一个样式声明具有高于其它样式的优先级。”id“比class更重要。

用这种方法,我们可以在自己的文件中重写那些被class设定的规则(比如宽度,padding,边框等)。


补充

以下是我做的一个简单的测试页面,代码如下:

  1. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  2. <htmlxmlns="http://www.w3.org/1999/xhtml">
  3. <head>
  4. <metahttp-equiv="Content-Type"content="text/html;charset=gb2312"/>
  5. <title>TESTPage</title>
  6. <linkhref="css/960.css"rel="stylesheet"type="text/css"/>
  7. <linkhref="css/reset.css"rel="stylesheet"type="text/css"/>
  8. <linkhref="css/text.css"rel="stylesheet"type="text/css"/>
  9. </head>
  10. <body>
  11. <divclass="container_16">
  12. <divclass="grid_8"style="background-color:#FF0000">
  13. <divclass="grid_6omega"style="background-color:#0000FF">0</div>
  14. <divclass="grid_2omega"style="background-color:#FF00FF">00</div>
  15. </div>
  16. <divclass="grid_4"style="background-color:#00FF00">a</div>
  17. <divclass="grid_2"style="background-color:#666666">b</div>
  18. <divclass="grid_2"style="background-color:#666666">c</div>
  19. </div>
  20. </body>
  21. </html>

以下是960官方的实例文档,可以看看它的网格是如何写的:

  1. <!--2009-From-http://travisisaacs.com/-->
  2. <!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  3. <htmlxmlns="http://www.w3.org/1999/xhtml"dir="ltr"lang="en-US">
  4. <headprofile="http://gmpg.org/xfn/11">
  5. <metahttp-equiv="Content-Type"content="text/html;charset=UTF-8"/>
  6. <title>TravisIsaacs|MyLifeInPixels</title>
  7. <metaname="keywords"content="photoshop,wordpress,userexperience,ux,uxd,ixd,interactiondesigner,interactiondesign,keynote,powerpoint,xhtml,css,webdesign,mac,timemachine,superduper,backup,aperture,canon,40d,viewzi,viewmix,views,lensrentals,lensrentals.com,infinitescrolling,cameralensrentaldallas"/>
  8. <linkrel="stylesheet"href="http://css.travisisaacs.com/2009/style.css"media="all"/>
  9. <!--[ifIE]>
  10. <linkrel="stylesheet"href="http://css.travisisaacs.com/2009/ie.css"media="all"/>
  11. <![endif]-->
  12. <linkrel="alternate"type="application/rss+xml"title="TravisIsaacs|MyLifeInPixelsRSSFeed"href="http://travisisaacs.com/feed/"/>
  13. <linkrel="pingback"href="http://travisisaacs.com/xmlrpc.php"/>
  14. <linkrel="shortcuticon"href="http://travisisaacs.com/favicon.ico"/>
  15. </head>
  16. <bodyid="TheIsaacsFamilyChristmasCard">
  17. <divid="header">
  18. <divclass="container_12">
  19. <ahref="http://travisisaacs.com"id="return-home"title="Gobacktothehomepage">Thework<spanclass="amp">&</span>thoughtsof<strong>TravisB.Isaacs</strong></a>
  20. <ulid="navigation">
  21. <liid="tab-work"><ahref="http://travisisaacs.com/work/">Work</a></li>
  22. <liid="tab-blog"><ahref="http://travisisaacs.com/thoughts/">Thoughts</a></li>
  23. <liid="tab-photography"><ahref="http://travisisaacs.com/photography/">Photography</a></li>
  24. <liid="tab-about"><ahref="http://travisisaacs.com/about/">About</a></li>
  25. <liid="tab-contact"><ahref="http://travisisaacs.com/contact/">Contact</a></li>
  26. <liid="tab-search"><scripttype="text/javascript"language="Javascript"src="http://vfp.viewzi.com/includes/879F-4A21-011D.js"></script></li>
  27. </ul>
  28. </div>
  29. </div>
  30. <divclass="ie-center"><!--closedinfooter-->
  31. <divclass="container_12">
  32. <divid="super">
  33. <h1>Hello.I'm<ahref="http://travisisaacs.com/about/">TravisIsaacs</a>,andIdesigngreatuserexperiences.</h1>
  34. </div>
  35. <divid="content">
  36. <divid="recent-post"class="grid_8alpha">
  37. <divclass="post">
  38. <h2>
  39. <ahref="http://travisisaacs.com/2008/12/13/the-isaacs-family-christmas-card/"rel="bookmark"title="PermanentLinktoTheIsaacsFamilyChristmasCard">
  40. TheIsaacsFamilyChristmasCard</a>
  41. </h2>
  42. <divclass="post-date">
  43. Dec13th//
  44. <spanclass="comment-count">
  45. 11comments</span>
  46. </div>
  47. <p>WhenplanningourfamilyChristmascardthisyear,mywifeandIdiscusstheoptionofhiringaprofessionalphotographertotakephotosofourdaughter.However,wethoughtitwouldbemuchmorefunandrewardingtodoitourselves.</p>
  48. <ahref="http://travisisaacs.com/2008/12/13/the-isaacs-family-christmas-card/"rel="bookmark"title="PermanentLinktoTheIsaacsFamilyChristmasCard"><strong>Keepreading»</strong></a>
  49. </div><!--/post-->
  50. </div><!--/recent-post-->
  51. <divid="recent-work"class="grid_4omega">
  52. <divclass="m_group"id="hello">
  53. <p>I'mTravisIsaacs,adesignerwhodabblesincode,informationarchitecture,andinteractiondesign.<ahref="http://travisisaacs.com/about/">Moreaboutme</a></p>
  54. </div>
  55. <ahref="http://travisisaacs.com/feed/"id="subscribe">Subscribe</a>
  56. </div>
  57. <divclass="clear"></div>
  58. <h2>FeaturedWork</h2>
  59. <ahref="http://travisisaacs.com/work/projects/tattoo-information-form/"id="featured-work-img"title="Viewthisproject">
  60. <imgsrc="http://img.travisisaacs.com/2009/featured-work-large.jpg"alt="featuredwork:tattoinformationsheet"/>
  61. </a>
  62. <divclass="clear"></div>
  63. </div><!--/content-->
  64. <divclass="clear"></div>
  65. </div><!--/container12-->
  66. <divclass="clear"></div>
  67. <divclass="clear"></div>
  68. <divid="footer"class="container_12">
  69. <ul>
  70. <li><ahref="http://travisisaacs.com">Home</a></li>
  71. <li><ahref="http://travisisaacs.com/work/">Work</a></li>
  72. <li><ahref="http://travisisaacs.com/thoughts/">Thoughts</a></li>
  73. <li><ahref="http://travisisaacs.com/photography/">Photography</a></li>
  74. <li><ahref="http://travisisaacs.com/about/">About</a></li>
  75. <li><ahref="http://travisisaacs.com/contact/">Contact</a></li>
  76. </ul>
  77. <divclass="copyright">©2008TravisIsaacs.AllRightsReserved.</div>
  78. </div>
  79. </div><!---/ie-center-->
  80. <scripttype="text/javascript">
  81. vargaJsHost=(("https:"==document.location.protocol)?"https://ssl.":"http://www.");
  82. document.write(unescape("%3Cscriptsrc='"+gaJsHost+"google-analytics.com/ga.js'type='text/javascript'%3E%3C/script%3E"));
  83. </script>
  84. <scripttype="text/javascript">
  85. try{
  86. varpageTracker=_gat._getTracker("UA-703764-4");
  87. pageTracker._trackPageview();
  88. }catch(err){}</script>
  89. <!--WoopraCodeStart-->
  90. <scripttype="text/javascript">
  91. var_wh=((document.location.protocol=='https:')?"https://sec1.woopra.com":"http://static.woopra.com");
  92. document.write(unescape("%3Cscriptsrc='"+_wh+"/js/woopra.js'type='text/javascript'%3E%3C/script%3E"));
  93. </script>
  94. <!--WoopraCodeEnd-->
  95. </body>
  96. </html>



<!--新Google 468*60横幅广告开始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; /* 468x60, 创建于 08-8-6 */ google_ad_slot = "7368701459"; google_ad_width = 468; google_ad_height = 60; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--新Google 468*60横幅广告结束-->

<!--新Google 468x15 横链接单元开始--><script type="text/javascript"><!-- google_ad_client = "pub-7343546549496470"; /* 468x15 横链接单元 */ google_ad_slot = "5785741422"; google_ad_width = 468; google_ad_height = 15; //--> </script><script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script><!--新Google 468x15 横链接单元结束-->

<!-- Google Reader shared发布代码开始 --><script type="text/javascript" src="http://www.google.com/reader/ui/publisher.js"></script><script type="text/javascript" src="http://www.google.com/reader/public/javascript/user/00697638153916680411/state/com.google/broadcast?n=5&amp;callback=GRC_p(%7Bc%3A%22green%22%2Ct%3A%22%5Cu8FD9%5Cu4E9B%5Cu6587%5Cu7AE0%5Cu4E5F%5Cu503C%5Cu5F97%5Cu4E00%5Cu770B%22%2Cs%3A%22false%22%7D)%3Bnew%20GRC"></script><!-- Google Reader shared发布代码结束 -->

你可能感兴趣的:(System)