Reader small image

You're reading from  Instant SASS CSS How-to

Product typeBook
Published inFeb 2013
PublisherPackt
ISBN-139781782163787
Edition1st Edition
Tools
Concepts
Right arrow
Author (1)
Alex Libby
Alex Libby
author image
Alex Libby

Alex Libby has a background in IT support. He has been involved in supporting end users for almost 20 years in a variety of different environments; a recent change in role now sees Alex working as an MVT test developer for a global distributor based in the UK. Although Alex gets to play with different technologies in his day job, his first true love has always been with the open source movement, and in particular experimenting with CSS/CSS3, jQuery, and HTML5. To date, Alex has written 11 books on subjects such as jQuery, HTML5 Video, SASS, and CSS for Packt, and has reviewed several more. Responsive Web Design with HTML5 and CSS3 Essentials is Alex's twelfth book for Packt, and second completed as a collaboration project.
Read more about Alex Libby

Right arrow

Using Compass in WordPress (Become an expert)


We've been through a real whistle stop tour of SASS and seen how it works – let's finish on a nice easy demo, which looks at how you can use Compass to provide vendor prefix support to our Bones theme in WordPress.

Getting ready

For this recipe, you will need your trusty text editor (preferably Sublime Text 2). You will also need Scout up and running, and configured to scan the \bones\library folder in your WordPress theme folder. We'll also need the Bones theme from the previous recipe. For the purposes of this recipe, I will assume that the settings remain unchanged from the previous task.

How to do it...

  1. Let's make a start by opening up a copy of the _mixins.scss file in the \bones\library\scss folder within the Bones theme. This contains all of the CSS3 mixins that we will work on.

  2. On or around line 18, add in the following line to call in Compass:

    @import "compass";
  3. Move down to the border-radius mixin, that starts on or around line 161:

  4. Let's comment out this mixin, as we're going to move to using the Compass version.

  5. Compass' version of border-radius is the same format as the one used in the Bones theme, so there is no need to change it in the Bones code. Go ahead and save your work. Check in the \bones\library\scss folder, you should find a freshly compiled style.css file. Copy this (and the other two – login.css and ie.css) to the css folder underneath \bones\library.

  6. To check that it has worked, open up the style.css file within \bones\library\css, and look for the .buttons class on or around line 638. You should find the compiled code for border-radius.

  7. Let's go for something little more involved – we will replace the box-shadow mixin, currently in use at line 204 with the version from Compass.

  8. Comment out the line at 287, and replace it with the following line (note that the order is reversed in comparison to that used by Bones):

    @include box-shadow(lighten($bones-blue, 16%) inset 0 0 3px);
  9. Save and recompile your work, then copy the updated CSS file to \bones\library\css. If you open up the style.css file from within that folder, you will find the box-shadow style in use at line 824.

How it works...

Although we've only scratched the surface with the changes we've made, it opens up a wealth of possibilities of what you can do in WordPress using Compass, or even any other similar mixin library. The same principle was used in both cases in this recipe – we've inserted a reference to Compass, found the mixin we're going to replace, and then removed the original. We've either left the original reference further down the _mixins.scss file as is, or altered it to fit in with the format used by Compass, then saved and recompiled the file.

One question that you may ask though is – why do it? The answer is simple: you could spend time maintaining vendor prefixes, which will come and go over time, or you could get someone to do it for you! There's no real technical necessity to do this, it is entirely up to you how you manage it, depending on what fits in best with your work environment.

Previous PageNext Page
You have been reading a chapter from
Instant SASS CSS How-to
Published in: Feb 2013Publisher: PacktISBN-13: 9781782163787
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Alex Libby

Alex Libby has a background in IT support. He has been involved in supporting end users for almost 20 years in a variety of different environments; a recent change in role now sees Alex working as an MVT test developer for a global distributor based in the UK. Although Alex gets to play with different technologies in his day job, his first true love has always been with the open source movement, and in particular experimenting with CSS/CSS3, jQuery, and HTML5. To date, Alex has written 11 books on subjects such as jQuery, HTML5 Video, SASS, and CSS for Packt, and has reviewed several more. Responsive Web Design with HTML5 and CSS3 Essentials is Alex's twelfth book for Packt, and second completed as a collaboration project.
Read more about Alex Libby