GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing lesscss.org — Getting started | Less.js
It's CSS, with just a little more.Use with Node.js: npm install -g less> lessc styles.less styles.css
Or the browser: <link rel="stylesheet/less" type="text/css" href="styles.less" /><script src="https://cdn.jsdelivr.net/npm/less" ></script>Or try
View the Less.js changelog
Because Less looks just like CSS, learning it is a breeze. Less only makes a few convenient additions to the CSS language, which is one of the reasons it can be learned so quickly.
What does Less add to CSS? Here's a quick overview of features. VariablesThese are pretty self-explanatory:
Outputs:
MixinsMixins are a way of including ("mixing in") a bunch of properties from one rule-set into another rule-set. So say we have the following class:
And we want to use these properties inside other rule-sets. Well, we just have to drop in the name of the class where we want the properties, like so:
The properties of the NestingLess gives you the ability to use nesting instead of, or in combination with cascading. Let's say we have the following CSS:
In Less, we can also write it this way:
The resulting code is more concise, and mimics the structure of your HTML. You can also bundle pseudo-selectors with your mixins using this method. Here's the classic clearfix hack, rewritten as a mixin (
Learn More About Parent Selectors Nested At-Rules and BubblingAt-rules such as
outputs:
OperationsArithmetical operations
Multiplication and division do not convert numbers. It would not be meaningful in most cases - a length multiplied by a length gives an area and css does not support specifying areas. Less will operate on numbers as they are and assign explicitly stated unit type to the result.
You can also do arithmetic on colors:
However, you may find Less's Color Functions more useful. From 4.0, No division is performed outside of parens using
You can change Math setting, if you want to make it always work, but not recommended. calc() exceptionReleased v3.0.0 For CSS compatibility,
EscapingEscaping allows you to use any arbitrary string as property or variable value. Anything inside
results in:
Note, as of Less 3.5, you can simply write:
In 3.5+, many cases previously requiring "quote-escaping" are not needed. FunctionsLess provides a variety of functions which transform colors, manipulate strings and do maths. They are documented fully in the function reference. Using them is pretty straightforward. The following example uses percentage to convert 0.5 to 50%, increases the saturation of a base color by 5% and then sets the background color to one that is lightened by 25% and spun by 8 degrees:
Namespaces and Accessors(Not to be confused with CSS Sometimes, you may want to group your mixins, for organizational purposes, or just to offer some encapsulation. You can do this pretty intuitively in Less. Say you want to bundle some mixins and variables under
Now if we want to mixin the
Note: append MapsAs of Less 3.5, you can also use mixins and rulesets as maps of values.
This outputs, as expected:
ScopeScope in Less is very similar to that of CSS. Variables and mixins are first looked for locally, and if they aren't found, it's inherited from the "parent" scope.
Like CSS custom properties, mixin and variable definitions do not have to be placed before a line where they are referenced. So the following Less code is identical to the previous example:
CommentsBoth block-style and inline comments may be used:
ImportingImporting works pretty much as expected. You can import a
|
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |