As you begin to develop web sites, you'll find that you often do the same
things over and over again when writing CSS.
At a minimum, you'll have to figure out how you want to deal with browser
inconsistencies, what type of layout styles to use, and what kind of typographic
treatment you'll use for your site.
Over time you'll find that you begin to develop a consistent way of handling
these issues thorough your styles.
In many ways, it would be advantageous to have a templating system in place to
speed up the process of generating those styles.
Well, that's where CSS frameworks come in.
CSS frameworks are pre-existing CSS libraries that are designed to give you a
starting point for your site's CSS, as well as to give you tools to make page
layout and typography faster to implement.
There are a lot of different CSS frameworks available, with a wide variety of
features, but as a general rule, here's how they work.
Most of the frameworks come with a style sheet that contains a base level set of styles.
These will typically contain a CSS reset to account for browser default styling,
baseline rules for common elements, basic rules for structural elements, and
rules that help with browser inconsistencies.
From there, the framework might include styles for form and table styling, styles
to control the site's typography, and a CSS grid for layout.
CSS grids allow you to quickly build multi-column layouts based on a specific grid.
The grids themselves might be based on a fixed size, a specific aspect ratio, or fluid columns.
Basically, they work by having pre-built classes that you can assign to
structural elements.
Those classes will control the width and layout of containers, making the
process of building your layout as simple as applying classes to the containing elements.
Developers will often build CSS grids as part of a larger framework, although
it's not uncommon to see them as stand-alone tools.
Now the choice to use or not use a CSS framework is entirely up to you or your team.
There are both pros and cons to using them,
so let's take a look at how to determine if a CSS framework is right for your project.
On the plus side, CSS frameworks can save you a lot of work, especially if
you're working on a larger site that requires multiple styling options.
They can also take the worry away about generating cross-browser compliant code.
In the most cases, this headache will be taken care of for you by the framework.
For frameworks that have grids built in, the process of generating layouts is much faster.
Many of the grids are designed to be extremely flexible and give you multiple
options for creating multi-column layouts.
Using a framework in the team environment also gives you a consistent code base
to work from, from the beginning.
This makes it easier to make sure that everyone's on the same page and that code
conventions are already in place.
Basically, if you use them correctly, a quality framework can lower the amount of
time that it takes you to create sites and ensure that you're using styles that
you know are going to work.
That doesn't mean, however, that they're not without their drawbacks.
Unless you're working on a really, really complex site, it's doubtful that you'll
use all of the features that a framework has to offer.
That means that often you have a lot of code in your styles that you're simply not using.
Many frameworks also come structured with multiple CSS files.
Now, this means that you either have to combine them yourself or be committed to
having links to multiple external style resources on every single page.
Another consideration is that most frameworks make heavy use of class styles, and
their classes often look something like this.
Now, while this means something to the framework,
it has no semantic bearing on your site,
so if you use a framework, be prepared to have class-heavy, non-semantic markup
throughout your site.
Frameworks can also be difficult to update, modify, and maintain.
Since you didn't write the code, finding specific styles that you want to modify
or overwrite can be a kind of difficult.
It can also be hard to add functionality not contained within the framework, as
the complex nature of the styles may cause conflicts with your custom styles.
Also, just because frameworks are designed to speed up site development, doesn't
mean that they're simple to use.
The more features a framework has, the more you're going to need to know exactly
what's going on in order to make it work efficiently.
In fact, I am going so far as to say that if you're a beginner, a framework
isn't necessarily a good idea.
You need to understand how the underlying CSS works in order to use them correctly.
However, they are great teaching tools. If you find a well-documented CSS
framework, learning to use it can be a great way of learning how to write
efficient cross-browser CSS.
I think one of the best ways is to decide whether a CSS framework is right for
you is to simply try one out,
so in our next movie I'll introduce you to some of the more popular CSS
frameworks to give you a starting point for your own research.