Start learning with our library of video tutorials taught by experts. Get started

CSS Fundamentals

Preprocessors


From:

CSS Fundamentals

with James Williamson

Video: Preprocessors

As powerful as CSS is, there are going to be times when you want to be able to do something that the language just won't let you do. Let me give you a quick example. Let's say that you use this color, which is a burgundy, throughout your entire site. Complex style sheets can contain hundreds of rules. Now, let's say that your client decides to use this flavor of burgundy instead. At this point, you'd better have a good find-and-replace option in your CSS editor, or you're going to be doing a lot of work by hand.

Watch this entire course now—plus get access to every course in the library. Each course includes high-quality videos taught by expert instructors.

Become a member
Please wait...
CSS Fundamentals
3h 14m Beginner Sep 26, 2011 Updated Dec 13, 2011

Viewers: in countries Watching now:

This course contains a high-level overview of Cascading Style Sheets, while exploring the basic concepts, terminology, and tools of the language. Beginning with an exploration of CSS syntax, author James Williamson explains how CSS modifies text, borders, backgrounds, and color; demonstrates CSS and HTML integration; and contextualizes the current state of CSS. The course also tours some of the most popular CSS editors and frameworks and lists online tools and resources for further study. This course is for people who want a big-picture overview before taking hands-on courses.

Topics include:
  • Understanding basic selector types
  • Integrating CSS with HTML
  • Examining browser rendering differences
  • Exploring CSS specifications
  • Checking browser support
  • Understanding the box model
  • Adjusting margins and padding
  • Positioning elements
  • Exploring basic layout concepts
  • Understanding media queries
  • Introducing CSS3
  • Using CSS Reset
Subjects:
Web Web Foundations
Software:
CSS
Author:
James Williamson

Preprocessors

As powerful as CSS is, there are going to be times when you want to be able to do something that the language just won't let you do. Let me give you a quick example. Let's say that you use this color, which is a burgundy, throughout your entire site. Complex style sheets can contain hundreds of rules. Now, let's say that your client decides to use this flavor of burgundy instead. At this point, you'd better have a good find-and-replace option in your CSS editor, or you're going to be doing a lot of work by hand.

Wouldn't it be easier if you could simply declare a variable for the color at the top of your styles and then reference that variable throughout your code? To change the color site-wide, you could just simply change the color of the variable. Well, that would be great, but you can't do that with CSS--at least not yet. Well, that's where CSS preprocessors come in. CSS preprocessors are programs created to extend the functionality of CSS and make it easier for authors to write their code. They work by allowing authors to write styles using the preprocessor's extended syntax.

This code is then processed by JavaScript or server-side languages, like PHP and Rails, and then generates styles for the browser. Most of the features of a CSS preprocessor are a little beyond the scope of this title, as they begin to move CSS away from a strictly presentational syntax to more of a processing language. However, I do want to give you a brief overview of some of the things that preprocessors allow us to do. We've already mentioned variables, and most preprocessors add those to the mix.

Others allow you to nest rules in much the same way that HTML does, which can make writing styles a bit faster and a lot easier. You can also take class selectors and reuse them in other styles. This ability to mix in styles from one rule to another is an incredibly powerful way to write more efficient styles. Some preprocessors even allow you to pass values into a class, so that the class covers the basic styling of an element, while different values allow you to tweak it in each rule that references it.

In most cases, you can also use operators. Now these allow us to do things like have the margin of one element equal to the margin of another element, plus another number. Now, that way, if the first element changes, the second element would maintain its spacing. Other preprocessors allow you to write simplified code for the new CSS3 features, adding the appropriate vendor prefixes and support for older browsers for you, after the code is processed. While CSS preprocessors are amazingly powerful, they aren't for everyone.

Now first, you have to learn how they work and the syntax necessary for the preprocessor to work. In many ways, it's like learning a new language all over again. Second, your CSS is abstracted from you in a way that's not always acceptable. The CSS is processed and served to the browser when requested, meaning that the author doesn't always see the end result. The resulting CSS is often much less efficient than it would be if carefully authored by a designer. In many cases, JavaScript is required to process the CSS.

In the event that a user has JavaScript disabled, your styles could end up malformed, or not even served at all. Perhaps the final point about preprocessors has really nothing to do with them. Many of the capabilities that preprocessors add to CSS are currently being added through CSS3. Eventually we should be able do the bulk of what preprocessors help us do without using them at all. I also want to caution any new designers out there: preprocessors and their syntax can be very complex.

If you don't understand CSS or are just learning it, I wouldn't recommend a preprocessor until you're a little bit more comfortable with the native syntax of CSS. Of course, as with any tool, you need to decide for yourself if a preprocessor is right for your projects or not. Now, researching and experimenting with them is perhaps the best way to judge for yourself how effective they would be in your own workflow. So, let's take a look. Of the available CSS preprocessors, LESS and SASS are by far the most popular.

LESS, which you can find at lesscss.org, uses syntax that's very similar to CSS's existing syntax, making it very popular with designers and easier to learn for those that might know CSS but maybe aren't as fluent with JavaScript or other scripting languages. SASS, which you can find at sass-lang.com, actually has two syntaxes that you can use: the older default syntax which has more in common with scripting languages, or the new Sassy CSS syntax that's designed to be a bit more like CSS.

After checking out those two, you might want to spend some time exploring Turbine, Switch CSS, CSS Cacheer, CSS Preprocessor, and PCSS. Each has its own unique focus, and they come in varying degrees of complexity. Now CSS preprocessors certainly aren't for everyone, and they usually require a fair amount of experience to implement effectively. They are, however, extremely powerful tools designed to extend CSS and make writing it more efficient.

That alone makes them worth exploring.

Find answers to the most frequently asked questions about CSS Fundamentals.


Expand all | Collapse all
Please wait...
Q: This course was updated on 12/13/2011. Can you tell me what has changed?
A: One movie called "Who is this course for?" was added to provide information on what you can expect to get from the course, depending on your level of familiarity with CSS.
Share a link to this course
Please wait... Please wait...
Upgrade to get access to exercise files.

Exercise files video

How to use exercise files.

Learn by watching, listening, and doing, Exercise files are the same files the author uses in the course, so you can download them and follow along Premium memberships include access to all exercise files in the library.
Upgrade now


Exercise files

Exercise files video

How to use exercise files.

For additional information on downloading and using exercise files, watch our instructional video or read the instructions in the FAQ.

This course includes free exercise files, so you can practice while you watch the course. To access all the exercise files in our library, become a Premium Member.

Upgrade now

Are you sure you want to mark all the videos in this course as unwatched?

This will not affect your course history, your reports, or your certificates of completion for this course.


Mark all as unwatched Cancel

Congratulations

You have completed CSS Fundamentals.

Return to your organization's learning portal to continue training, or close this page.


OK
Become a member to add this course to a playlist

Join today and get unlimited access to the entire library of video courses—and create as many playlists as you like.

Get started

Already a member?

Become a member to like this course.

Join today and get unlimited access to the entire library of video courses.

Get started

Already a member?

Exercise files

Learn by watching, listening, and doing! Exercise files are the same files the author uses in the course, so you can download them and follow along. Exercise files are available with all Premium memberships. Learn more

Get started

Already a Premium member?

Exercise files video

How to use exercise files.

Ask a question

Thanks for contacting us.
You’ll hear from our Customer Service team within 24 hours.

Please enter the text shown below:

The classic layout automatically defaults to the latest Flash Player.

To choose a different player, hold the cursor over your name at the top right of any lynda.com page and choose Site preferencesfrom the dropdown menu.

Continue to classic layout Stay on new layout
Welcome to the redesigned course page.

We’ve moved some things around, and now you can



Exercise files

Access exercise files from a button right under the course name.

Mark videos as unwatched

Remove icons showing you already watched videos if you want to start over.

Control your viewing experience

Make the video wide, narrow, full-screen, or pop the player out of the page into its own window.

Interactive transcripts

Click on text in the transcript to jump to that spot in the video. As the video plays, the relevant spot in the transcript will be highlighted.

Thanks for signing up.

We’ll send you a confirmation email shortly.


Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

Keep up with news, tips, and latest courses with emails from lynda.com.

Sign up and receive emails about lynda.com and our online training library:

Here’s our privacy policy with more details about how we handle your information.

   
submit Lightbox submit clicked