{"id":5390,"date":"2011-02-21T21:37:00","date_gmt":"2011-02-21T20:37:00","guid":{"rendered":"http:\/\/www.chipwreck.de\/blog\/?p=5390"},"modified":"2022-07-05T17:38:22","modified_gmt":"2022-07-05T15:38:22","slug":"lesscss","status":"publish","type":"post","link":"https:\/\/www.chipwreck.de\/blog\/2011\/02\/21\/lesscss\/","title":{"rendered":"LessCSS &#8211; a short introduction"},"content":{"rendered":"\n<h3 class=\"wp-block-heading\">What is LessCSS?<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">It&#8217;s a CSS extension which improves the CSS syntax with variables, inheritance, nested rules and other features.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em>This post is more than 10 years old, so please regard this as outdated.<\/em><\/p>\n\n\n\n<!--more-->\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"199\" height=\"81\" src=\"https:\/\/www.chipwreck.de\/blog\/wp-content\/uploads\/2011\/02\/less.png\" alt=\"LessCSS Logo\" class=\"wp-image-6024\" title=\"less\" srcset=\"https:\/\/www.chipwreck.de\/blog\/wp-content\/uploads\/2011\/02\/less.png 199w, https:\/\/www.chipwreck.de\/blog\/wp-content\/uploads\/2011\/02\/less-120x48.png 120w\" sizes=\"auto, (max-width: 199px) 100vw, 199px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\">Examples, please<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A short example:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">@linkcolor:\t\t#9999C9;\n@spacing_left:\t\t60px;\n\n.rounded(@radius: 3px) {\n    -webkit-border-radius: @radius;\n    -moz-border-radius: @radius;\n    border-radius: @radius;\n}\n\n.navi {\n\t.rounded(5px);\n\ta {\n\t\tcolor: @linkcolor;\n\t}\n}\n\ndiv.navigation {\n\tpadding-left: @spacing_left;\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">So you can define variables (like colors, distances etc.), which then can be used in the rest of the file &#8211; great to have all used colors in one place only. Furthermore there are user-defined <q>functions<\/q>, like <q>.rounded<\/q> here, a shortcut to add the three possible border-radius methods. You can even add parameters (in this case radius) with a default value. And nested classes (.navi a) can be written more naturally.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">And there&#8217;s more<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">There are also operators and functions:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">.darker {\n\tcolor: darken(@mycolor, 10%);\n\tbackground-color: lighten(@mybg, 15%);\n\tpadding-right: @spacing_left * 2;\n\tpadding-bottom: (@spacing_left + 5) * 2;\n}\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">A complete list of all possible features can be found on the <a class=\"external\" href=\"http:\/\/lesscss.org\/#docs\">lesscss.org<\/a> website.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">How to use<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">So we&#8217;ve got a kind of CSS+ with one single disadvantage &#8211; not a single browser can understand LessCSS. Therefore the .less-files have to be &#8220;compiled&#8221; (=translated to ordinary CSS) before they&#8217;re sent to the Browser. There are different ways: You can automatically compile them on the server (usually with PHP), or you can use <q>less.js<\/q>, a javascript which handles the translation in the frontend &#8211; or you can use Less.app (Mac only).<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><a class=\"external\" href=\"http:\/\/lesscss.org\/#-client-side-usage\">Less.js<\/a> is quite easy to use: Instead of including the css-file you simply put this in your (development) page header:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;link rel=\"stylesheet\/less\" type=\"text\/css\" href=\"site.less\"&gt;\n&lt;script type=\"text\/javascript\" src=\"less-1.0.41.min.js\"&gt;&lt;\/script&gt;\n<\/pre>\n\n\n\n<p class=\"wp-block-paragraph\"><a class=\"external\" href=\"http:\/\/incident57.com\/coda\/index2.php\">Less.app<\/a> is a great OS X application, which monitors the folders where you put your Less-files and automatically creates the corresponding CSS-file, with error checking and minification if desired.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">But&#8230;<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">I read some discussions on the web whether extending CSS is (by itself) a good idea or not. Most criticism is around these three points:<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">1. It&#8217;s an additional step in your development process\/adds another layer of complexity<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">Yes, so does mootools\/jquery and so does a CSS-reset. But would you recommed not using mootools\/jquery, because it&#8217;s an additional layer? Usually not. The additional complexity is there only once &#8211; at the beginning, when you have to learn LessCSS. As soon as you use it in the second or third project this initial effort soon begins to fade.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">2. Performance gets worse<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">If you include less.js and put everything online, this is true: The additional javascript and parsing takes a little bit more time. But less.js is IMHO not meant to be put online, it&#8217;s a <em>development tool<\/em>. So I recommend putting the resulting CSS file online and remove the less.js &#8211; much like you&#8217;d include a non compressed JS-library while debugging and the yc-compressed one later.<\/p>\n\n\n\n<h5 class=\"wp-block-heading\">3. You can&#8217;t debug correctly anymore<\/h5>\n\n\n\n<p class=\"wp-block-paragraph\">When using Firebug or a similar tool, you work with the resulting CSS. So the line numbers are not correct anymore and if you change values, you change them in the resulting classes only. That might be a valid point for some people &#8211; but maybe someone writes a firebug extension one day..<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">IDE\/Editor-Support<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Since LessCSS is quite a new development I was surprised that for example PHPStorm natively supports LessCSS &#8211; not only does it syntax highlighting, but also error checking, auto complete and <a class=\"external\" href=\"http:\/\/blogs.jetbrains.com\/webide\/tag\/less\/\">much more<\/a>. There are also syntax-modes <a class=\"external\" href=\"http:\/\/groups.google.com\/group\/coda-users\/browse_thread\/thread\/b3327b0cb893e439\">here<\/a>, <a class=\"external\" href=\"http:\/\/joebergantine.com\/werkstatt\/seestyle\">here<\/a> and <a class=\"external\" href=\"https:\/\/github.com\/monoceroi\/LESS.mode\">here<\/a> for Coda and some plugins for TextMate (<a class=\"external\" href=\"https:\/\/github.com\/kassens\/less.tmbundle\">here<\/a> or <a class=\"external\" href=\"https:\/\/github.com\/appden\/less.tmbundle#readme\">here<\/a>).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">More<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">More information about LessCSS can be found on the <a class=\"external\" href=\"http:\/\/lesscss.org\/\">lesscss website<\/a> or <a class=\"external\" href=\"http:\/\/designshack.co.uk\/articles\/css\/using-less-js-to-simplify-your-css3\">here<\/a> or <a class=\"external\" href=\"http:\/\/fadeyev.net\/2010\/06\/19\/lessjs-will-obsolete-css\/\">here<\/a>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">And checkout these <a class=\"external\" href=\"http:\/\/ku1ik.com\/blog\/2009\/07\/25\/lesscss-goodies.html\">LessCSS Goodies (in Ruby)<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"What is LessCSS? It&#8217;s a CSS extension which improves the CSS syntax with variables, inheritance, nested rules and other features. This post is more than 10 years old, so please regard this as outdated.","protected":false},"author":2,"featured_media":6024,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[8],"tags":[9,46,52,79],"class_list":["post-5390","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-webdevelopment","tag-css","tag-extension","tag-less","tag-webdesign"],"jetpack_shortlink":"https:\/\/wp.me\/saPEN-lesscss","jetpack_sharing_enabled":true,"jetpack_featured_media_url":"https:\/\/www.chipwreck.de\/blog\/wp-content\/uploads\/2011\/02\/less.png","_links":{"self":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts\/5390","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/comments?post=5390"}],"version-history":[{"count":2,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts\/5390\/revisions"}],"predecessor-version":[{"id":8332,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/posts\/5390\/revisions\/8332"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/media\/6024"}],"wp:attachment":[{"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/media?parent=5390"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/categories?post=5390"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.chipwreck.de\/blog\/wp-json\/wp\/v2\/tags?post=5390"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}