Quick Tip: You Need to Check out LESS.js
Tutorial Details
- Topic: Faster CSS
- Technology: JavaScript
- Estimated Completion Time: 4 Minutes
You might be familiar with such services as LESS and Sass. They allow for far more flexibility when creating your stylesheets, including the use of variables, operators, mix-ins, even nested selectors. However, because LESS was originally built with Ruby, a lot of PHP developers, despite the fact that there are PHP versions available, never used it.
That’s all going to change now that LESS is being rewritten in JavaScript, is about forty times faster than the Ruby version, and can be used by any of us!
Subscribe to our YouTube page to watch all of the video tutorials!
Prefer to watch this video on Screenr?
Step 1. Reference LESS.js
<script src="http://lesscss.googlecode.com/files/less-1.0.18.min.js"></script>
Step 2. Import a Stylesheet
<link rel="stylesheet/less" href="style.less" />
Note that we’ve set the rel attribute to “stylesheet/less,” and that our actual stylesheets has an extension of .less, not .css. Also, we must link to this stylesheet before Less.js.
Step 3. Have Fun!
With this minimal amount of work, you now have access to everything from variables to mix-ins. Be sure to watch the four minute video tutorial above for full examples, but here are a few quickies.
/*
Variables!
*/
@primary_color: green;
/*
Mix-ins are like functions for commonly used operations,
such as apply borders. We create variables by prepending
the @ symbol.
*/
.rounded(@radius: 5px) {
-moz-border-radius: @radius;
-webkit-border-radius: @radius;
border-radius: @radius;
}
#container {
/* References the variable we created above. */
background: @primary_color;
/* Calls the .rounded mix-in (function) that we created, and overrides the default value. */
.rounded(20px);
/* Nested selectors inherit their parent's selector as well. This allows for shorter code. */
a {
color: red;
}
}
It’s important to remember that LESS.js isn’t finished; hopefully, it will be soon. Nonetheless, it’s working wonderfully so far. What do you think?
- http://www.daniel-petrie.com Daniel Petrie
- http://net.tutsplus.com Jeffrey Way
- http://webitect.net/ Nick Parsons
- http://kory.gorsky.ca Kory Gorsky
- Peter
- http://webitect.net Nick Parsons
- http://onlineqrlab.com qr
- simon
- http://cloudica.net/ Sam
- John
- http://mediagearhead.com Giles
- Rich
- http://www.gradientgraphics.net Wes D
- http://davidfitzgibbon.com David Fitzgibbon
- http://mario.ec/ Mario
- w1sh
- http://mario.ec/ Mario
- http://davekingsnorth.com Dave Kingsnorth
- http://davekingsnorth.com Dave Kingsnorth
- http://sirestudios.com Tommy M.
- Jota Carlos
- http://shoxty.com Will
- http://www.johnwooten.info drumkeyjw
- http://envexlabs.com Matt Vickers
- simon
- http://danharper.me Dan Harper
- http://twitter.com/catshirt catshirt
- http://jacobdubail.com Jacob
- http://jamiebarrow.deviantart.com James Barrow
- http://www.marioawad.com Mario Awad
- w1sh
- w1sh
- buritica
- w1sh
- w1sh
- Paulo Vítor
- http://www.venture-ware.com/kevin/ Kevin Jensen
- http://www.xboxgamertag.com Gamertag
- http://envexlabs.com Matt Vickers
- Chris
- bootdisk
- bootdisk
- Markus
- http://www.mcmillangraphics.com Michael McMillan
- drumkeyjw
- http://thadknowsweb.com Thad Bloom
- buritica
- Andreas Madsen
- http://dagrevis.net/ daGrevis
- http://designfortress.com dreame4
- Ivo Trompert
- http://812studio.com benjamin
- http://812studio.com benjamin
- http://danstondin.com Daniel Stondin
- http://danstondin.com Daniel Stondin
- Ivo Trompert
- http://www.aediscreative.com Christopher Uryga
- http://www.acrylicstudios.com/en/ timeNomad
- http://matt-bridges.com/ Matt Bridges
- Michael
- Chris
- Rinaldo
- http://dazydude.net Rik de Vos
- http://www.pokerbanda.com Andrew
- Brad
- Hydraulics
- http://wildanr05.student.ipb.ac.id wildanr05
- Denis Molan
- http://kimhallberg.se/ Kim
- Ilias
- Ilias
- http://www.cbesslabs.com Bratu Sebastian
- http://www.xcellence-it.com/ Xcellence IT
- http://net.tutsplus.com Jeffrey Way
- http://www.xcellence-it.com/ Xcellence IT
- w1sh
- http://www.jordanwalker.net Jordan Walker
- http://www.xcellence-it.com Xcellence-IT
- http://www.mfx.ro marius
- Vin
- Vin
- Brad
- Joel
- http://aniwood.org Ryu
- http://blog.larsjung.de Lars
- http://www.jc-designs.net/blog Jeremy Carlson
- Joel
- Julius
- http://spotdex.com Davidmoreen
- http://67ideas.com Jack Hoge
- Greg McAusland
- Greg McAusland
- http://fishmemory.net frctalbit
