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?
- adrian
- http://67ideas.com Jack Hoge
- http://N/A jason
- http://www.guliwer.sk Jan
- Jacob
- http://codendesign.blogspot.com nXqd
- http://variable3.com/ Harsha M V
- http://bakasura.in/ Bakasura
- http://www.mo9a7i.com Mohannad Otaibi
- adrian
- Stephen
- http://stevendobbelaere.be Steven Dobbelaere
- http://davekingsnorth.com Dave Kingsnorth
- Dave
- Matanya
- http://www.webmasterdubai.com umefarooq
- tgmdbm
- http://www.enome.be Pickels
- http://www.enome.be Pickels
- http://iamoneman.com Paul Davis
- Leandro
- http://www.mediasumo.com Daniel
- http://www.mediasumo.com Daniel
- Paul
- http://gruvii.com Mark Figueredo
- http://www.joshuabriley.com Joshua Briley
- http://www.joshuabriley.com Joshua Briley
- http:www.exactaindy.com Sean
- http://blog.enome.be Pick
- http://createmy.com.au Dale Hurley
- http://createmy.com.au Dale Hurley
- Jesus
- http://www.markupmypage.com Kim
- Mike
- http://fredkelly.net Fred Kelly
- http://www.pangomedia.se/ Christian
- Nathan Buchanan
- http://asd.asd notme
- http://www.tenaxtechnologies.com java developer
- http://codendesign.blogspot.com nXqd
- http://www.joshuabriley.com Joshua Briley
- Joshua Briley
- Joshua Briley
- Matthew Wehrly
- Marcel
- http://www.jmonit.com Monit
- http://buzzknow.com/feed Buzzknow
- http://ahrengot.com/ Jens Ahrengot Boddum
- YoniPacheko
- chok
- cavo789
- http://winless.org Mark Lagendijk
- Tony
- http://www.scriptingwithajax.com stylinchas
- sana
