[zz]A Closer Look At the Blueprint CSS Framework

[my own word]转载还是不转载,这个问题似乎纠结了我很久,有一段时间甚至将我所转的自己喜欢的文章全部删除了,因为我忽然觉得我自己也要为这种信息爆炸负责;但是一方面我发现自己的力量微不足道,另一方面我突然觉得如果是有用的信息好的信息爆炸的话也未尝不是件好事,只是深入继续探讨下去又会有人追我(如何定义好),没办法我还是活在当下,向关注这个领域的人推荐些我喜欢的东西吧,我想这应该是对他们有帮助的东西。真心的希望我不曾浪费来阅读我博客的读者的时间,如果有这样的博文,请务必转告我将其删除,万万不可让其祸害众人。

Blueprint is a CSS framework that can save you time and headaches when working on any project that involves HTML and CSS, whether it be with Rails, PHP, or just laying out an HTML page. In this tutorial you will get a look at the inner workings of Blueprint and we'll take a look at demo application that uses Blueprint to get a better idea of how to use actually use the framework.

PG

Author: Jesse Storimer

I'm Jesse. I live in Ottawa, Canada. I'm currently interested in Rails and all things that make web development easier. I have a blog too.

What is Blueprint CSS?

[zz]A Closer Look At the Blueprint CSS Framework_第1张图片

If you are like me, as in more of a developer than a designer, then you are familiar with the process of starting a new project and not knowing what to do with your CSS. You know that your design will likely change as the project goes on, but you want to have a nice looking design from the beginning. So you spend some time writing some CSS that works in Firefox and Safari, oh wait, don't forget IE, right, right. Then you write some HTML that you think you will use, and work at getting all of the spacing to look right. Great! Finished! Now, three days later, the requirements for your project have changed and you find yourself redesigning the layout again. Hmm...

Now, even if you are a rockstar designer who already has all this CSS stuff figured out, or if you aren't worried about how your layout will change over time because you are working from a PSD template or something, that doesn't mean that there is nothing to learn here. Blueprint can still provide you with some tools so you can...

Spend your time innovating, not replicating.

This is the motto advertised on blueprintcss.org And I think that this is exactly what Blueprint accomplishes. Blueprint provides a solid foundation to build your project on top of. It does this by providing sensible defaults across all browsers, nice-looking default typography, a grid framework, nice-looking forms, and a print stylesheet built with printers in mind. Let's take a look at how Blueprint achieves this:

Blueprint Source Files
  1. reset.css This file sets sensible defaults across all browsers. I'm sure we are all familiar with starting a new project, going to our main CSS file and adding a few default styles to the body selector, such as 'margin: 0; padding:0; font-family: Helvetica, Arial, sans-serif;' or something along those lines. This is what reset.css does, and more. It resets default styles for spacing, tables, fonts, etc. so you can work from a clean slate.

  2. typography.css This file sets up some nice default typography. I won't explain all of the styles but I will say that this is my favourite parts of Blueprint because, to me, there is nothing more discouraging than trying to lay out a page and seeing some black Times New Roman text jammed up into the top left corner of a page. Ugh. Blueprint's typography.css keeps me from ever seeing that again. The typography.css also sets up some really nice styles around font sizes, line-heights, default styling of tables, etc.

  3. grid.css This file handles the grid layout portion of blueprint. We will have a look at the classes that it uses in a bit. One important thing to note with the grid, by default it uses a width of 950px, with 24 columns each having a width of 30px and a 10px margin between columns. This may sound constrictive, but if this is not the layout you want, you can always use a Blueprint Grid CSS Generator to generate a custom grid layout. If this last paragraph completely confused you, please read on as we will build a layout using a grid in a bit. If you are not familiar with CSS grid layouts and want some background, Raj's Which CSS Grid Framework Should You Use for Web Design? is a good intro.

  4. ie.css Blueprint supports IE, so of course it needs it's own specific stylesheet to take care of those little details that makes IE so special :) The nice thing is that Blueprint does handle this for you, so all of its core styles will work in all of the major browsers (I think it even supports IE 5).

  5. print.css This file sets some default print styles, so that printed versions of your site looks better than they usually would. The print.css file also has an option where you can fill in your domain name so that relative links are shown in parentheses behind the text link in the printed version of your page. Without filling in this section only remote links will print properly. Check out the bottom of the print.css src file, linked above.

  6. forms.css This file provides nice looking default forms as well as classes for error notifications or even flash notifications if you are using something like Rails. Since this is the only section I will not cover in more detail, here is some of the default form styles in use:

    [zz]A Closer Look At the Blueprint CSS Framework_第2张图片

Does this mean that I have to include six different stylesheets?

No. Blueprint comes with three compressed stylesheets for your HTML pages, screen.css which contains #'s 1-3 & 6 from above, print.css, and ie.css. The reason that I outlined the different parts of the framework above is because the framework is modular, each of those pieces works independently of each other. The nice thing about this is that if you decide that one aspect of Blueprint, such as a grid layout, doesn't fit your project but you still want the benefits of reset.css and typography.css, you don't have to use the the grid but the other styles will still work.

Let's Build a Layout with Blueprint

[zz]A Closer Look At the Blueprint CSS Framework_第3张图片

This site is an idea that I had kicking around in my brain so I thought I would bring it to life here. It's a site where people who like to write novels as a hobby can go to review novels from other hobby writers as well as upload their own to be reviewed.

I realize that all of you rockstar designers who stuck around at the start are now about to leave after taking a look at my design, but the interesting thing about this design is that I did not write any CSS for it. This design uses only Blueprint styles and while it's not the end of all designs, it provides a flexible, nice-looking design for my project. Since my design is likely change, Blueprint makes it easy to update my layout, and when my site is fully functional, I can think about adding some of my own styling to make things look prettier.

Break it Down

The head of the document

view plaincopy to clipboardprint?

  1. Book Haven
    
      Book Haven
This is how a typical tag should look when you are using Blueprint. You need to include the framework's CSS files, which consists of screen.css, print.css and ie.css.

A great thing about Blueprint: it's just CSS, so it can be overridden like any other CSS. This is how Blueprint plugins work. In this example I am using the Blueprint fancy-type plugin which offers some fancy typography styling. You can see that I've linked to the fancy-type CSS file below the framework's CSS files, so the fancy-type CSS has the ability to overwrite styles defined by the framework. To this end, there are several BP plugins available which simply overwrite aspects of the framework or add new styles for you to use.

Lastly you should include your CSS file where you could overwrite styles from the framework and add your own styling to the page.

The Page Header

[zz]A Closer Look At the Blueprint CSS Framework_第4张图片

    
      

Get opinions on your latest novel, and read what other people are writing about.


The most important thing to note about this code: your grid must be surrounded by a
with a class of 'container' otherwise it will not display as a grid. The
tags are used by Blueprint to separate sections of your page vertically. The 'alt' class is brought to you by the fancy-type plugin and provides a nice way to spice up some text (can be applied to any text element).

Main Content

[zz]A Closer Look At the Blueprint CSS Framework_第5张图片

view plaincopy to clipboardprint?

  1. Featured Book: "The World Without Us"

  2. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
  3. Cras sagittis. Fusce porttitor felis sed massa. In hac habitasse platea dictumst.

  4. Upload a Book

  5. Nam vitae tortor id ante sodales facilisis.

Write a Review

Nam vitae tortor id ante sodales facilisis. Mauris ipsum.

Recent Books

Hygiene
Nov. 29, 2008
by Craven

Recent Reviews

Thor reviewed Hygiene
Rating: 4/5
Read this review
    

Featured Book: "The World Without Us"

Lorem ipsum dolor sit amet, consectetuer adipiscing elit.

Cras sagittis. Fusce porttitor felis sed massa. In hac habitasse platea dictumst.


Upload a Book

Nam vitae tortor id ante sodales facilisis.

Write a Review

Nam vitae tortor id ante sodales facilisis. Mauris ipsum.

Recent Books

Hygiene
Nov. 29, 2008
by Craven

Recent Reviews

Thor reviewed Hygiene
Rating: 4/5
Read this review

There is lots of important stuff in this code snippet! Let's start at the top with
. This tag declares the largest outlined div on that page, the one that contains the Featured Book section as well as the two smaller sections below. The class 'span-17' relates to the Blueprint grid layout. It declares that the width of this div should span 17 of the 24 columns on the page. The other class being used, 'colborder', is short for column border and tells Blueprint to put a border to the right of this div between it and the sidebar.

Important: using the 'colborder' class actually takes up an entire column. Since our main div is using 17 columns (span-17), you would expect that the sidebar could occupy 7 columns (since 17 + 7 = 24, the number of columns on our page), but since the 'colborder' property takes up a column to itself, this leaves only 6 columns left for the sidebar div to occupy (17 + 1 + 6 = 24).

Before we get to the sidebar we need to look at those two smaller div's, the ones titled 'Upload a Book' and 'Write a Review'. This is actually one Blueprint grid nested another Blueprint grid. Since the inner grid is nested inside a div spanning 17 columns, the max width for this grid, instead of 24, is 17.

So, the first div has the classes 'span-8' and 'colborder', meaning it's width will span 8 columns and it will have a border to the right. The second div here has classes 'span-8' and 'last'. This is an important part of the Blueprint grid framework. The rightmost column in a grid must have use the 'last' class. This tells BP that this is the last column in this grid and it doesn't need to make space for any more. Notice how we had room for 17 columns to begin with, each of the divs spanned 8 columns and the 'colborder' property took up the last column (8 + 8 + 1 = 17).

OK, back to the sidebar. The sidebar div has classes of 'span-6' and 'last'. I'm sure you guys have caught on now to how these classes work. This sidebar completes the grid that the main span-17 div began. In case you didn't notice, the 'span-#' class can take any number between 1 and 24, unless you decide to use a bigger grid, in which case the 'span-#' class can take any number so long as the number is less than the total number of columns in your grid.

This is about the simplest HTML I could come up with to demonstrate the grid.

view plaincopy to clipboardprint?

  1. Header
Left sidebar
Main content
Right sidebar
    
Header
Left sidebar
Main content
Right sidebar

Let's look at a few more of the CSS classes that we used in the layout.

  1. 'caps': This class is used in the sidebar titles. It is brought to us by the fancy-type plugin and provides nice styling for capitalized titles.
  2. 'box': This is a great one for displaying list items. It easily distinguished these items from the rest of the page and provides a nice margin between elements and nice padding for the elements inside.
  3. 'quiet': This is a CSS class that changes the color of text to be that soft grey that you see in the sidebar text.
  4. 'prepend-top': This one is used on the 'Recent Reviews' section of the sidebar. It simply applies a margin of 1.5em to the top of the element. There is a similar class called 'append-bottom' which has the same effect on the bottom of an element.
  5. 'prepend-5': I am using this class to push the titles in the smaller div's to the right. In Blueprint there are several classes for spacing: prepend, append, pull, and push. Prepend and append add padding to the left and right, respectively. Pull and push add a margin to the left and right, respectively. Once again, you can do as much appending, prepending, pulling, and pushing as you want so long as you don't use a number bigger than the total number of columns in your grid (such as prepend-25 in a grid with 24 columns).

    Footer Design Breakdown

If you are not familiar with the CSS box model and don't know the difference between padding and margin, here is a a brief lesson. In CSS, padding adds space within the borders of the element and actually increases the size of the element. For example, if you have a table with borders and you add padding to that table, it will actually push the borders away from the table. Margin, on the other hand, adds space outside of the border and does not increase the size of the element. This may have the effect of push other elements away from the current one or moving the current element on the page. Here is a great image to demonstrate the CSS box model:

[zz]A Closer Look At the Blueprint CSS Framework_第6张图片

[zz]A Closer Look At the Blueprint CSS Framework_第7张图片

Summary

This tutorial intended to show you how Blueprint CSS can be used to lay the groundwork for your next project, or at least take some of the weight off of your shoulders around resets and typography. Also, if you are using Blueprint with Rails, check out their repository on Github as they have some features that allow you to easily integrate and configure Blueprint to work with your Rails project.

The best thing about Blueprint is that it's just CSS. It's all CSS. So if you are interested in Blueprint go check out the source and if you have any knowledge of CSS you should be able to understand how it all works. Blueprint also is not a very large code base, it probably has less CSS than most of us use on a typical project. You can even read the source in your browser over at the Blueprint repository on Github.

你可能感兴趣的:(CSS,IE,Rails,UP,Safari)