Joomla LESS
From Joomla! Documentation
Most of the Joomla 3.0 default template stylesheets are written using LESS and then compiled to generate the CSS files.
Where can you find the .less stylesheets and compiler?
The .less
building blocks are located in media/jui/less/
. The template specific .less
files are located in templates/<templates>/less/
.
The CSS generation wrapper script, LESS compiler, and other similar build tools are located in the build/
directory of the Joomla source located on GitHub. Refer to Git for Coders for more information on using GitHub. The build directory is only available from the Joomla source, it is not included in an official Joomla release.
How to re-generate the CSS stylesheets
To re-generate all the CSS files from a Joomla core distribution, you will need to execute the generation scripts as a CLI application.
For example:
cd joomla-cms/build c:\xampp\php\php.exe generatecss.php
Compiling your own LESS files for your template
To compile less files for your own template, you will need to take a copy of the generatecss.php
script and adjust it to suit your template.
Alternatively you can use a LESS Compiler plugin which compiles your .less files automatically on page reload: http://extensions.joomla.org/extensions/miscellaneous/development/22424
More alternatives and tools on a recent Joomla! Magazine article: http://magazine.joomla.org/issues/issue-may-2013/item/1289-tools-to-do-less
Not all LESS compilers are equal
The LESS compiler used for the Joomla core for code style consistency is obtained from leafo.net/lessphp.
If you're working on your own template you can use any compiler you like.
Difference CSS vs LESS imports
The main .less file and starting point e.g. in protostar is located in
/templates/protostar/less/template.less
If you open that file you will find many @imports in this file - imports from many different places. Unlike imports in CSS, imports in LESS get compiled to a single CSS file. This will result in fewer http requests and speed your site up.
From existing CSS to LESS / import CSS files
You may want to add your existing CSS files and classes to your LESS powered template or start with what you have. All CSS declarations are compatible with LESS so you can just rename your .css files to .less and you can compile and use them. You can then step by step make use of the great dynamic features LESS has to offer: variables, mixins, operations and functions. See http://www.lesscss.org
Notice: the examples below reference the default Protostar template for clarity. Your paths may be different. Notice: If you want to customize Protostar template it is a good idea to copy the template and customize it afterwards - so that Joomla! updates do not overwrite your customizations.
Option 1: import your .css as .less files
(a little bit work but worth it, imho)
Now lets assume you want to include your custom files and get them parsed by LESS compiler - you do NOT need to rewrite your .css to LESS because plain .css works as well. The only thing you have to do is to rename your .css files to .less and add an @import statement into above mentioned main /templates/protostar/less/template.less
I assume you put your custom .css files renamed to .less into the /templates/protostar/less folder. Now you open /templates/protostar/less/template.less and at the bottom of the file you import your custom .less files so that they override existing declarations:
@import "modules.less"; @import "components.less"; @import "articles.less";
If you now compile your main template.less file you end up with one main template.css optimized and minified (if you wish). You also reduced your http requests and the site should load faster. Now you can start step by step in your custom.less files to use less variables and other cool stuff http://lesscss.org has to offer.
Option 2: just import your .css / does not work for overriding
In /templates/protostar/less/template.less just import your .css files and they will be included as imports into main template.css:
@import "../css/modules.css"; @import "../css/components.css"; @import "../css/articles.css";
But this way you do not get any optimization. And a big issue is that this import is always on top before other declarations - so you can't override an existing declaration.
More information: http://lesscss.org/#usage (Section Importing)
References
http://kyleledbetter.com/jui/less/ - Example of building your own template.less