Language

From Documentation
Revision as of 10:12, 11 November 2011 by Tomyeh (talk | contribs) (→‎Mixin Usage)



Variables

Variable Definition

@name: value;
@name: expression;

Example,

@nice-blue: #5B83AD;
@light-blue: @nice-blue + #111;

The name must be composed of letters, numbers, the underscore (_) and the dash (-).

Variable Usage

@name

Example,

@nice-blue: #5B83AD;
@light-blue: @nice-blue + #111;
@dark-orange: orange - #010203; /*orange is a standard color.*/

div.hilite { color: @light-blue;}
div.hilite2 { color: @dark-orange;}

Outputs:

div.hilite { color:  #6c94be;}
div.hilite2 { color: #fea300;}

Mixins

Mixin Definition

@name (@argument-name: default-value, @argument-name: default-value) {
  ZUSS content
}

Example,

@border_radious(@radius: 4px) {
  border-radius: @radius;
  -moz-border-radius: @radius;
  -webkit-border-radius: @radius;
}

The name must be composed of letters, numbers, and the underscore. The name may only begin with a letter and the underscore.

Mixin Usage

@name(expression 1, 'expression 2);

Example,

@border_radious(@radius: 4px) {
  border-radius: @radius;
}

div.rounded {
  @border_radious();
}
button.rounded {
  @border_radious(3px);
}

Outputs:

div.rounded {
  border-radius: 4px;
}
button.rounded {
  border-radius: 3px;
}

In additions, within the definition of a mixin, you coud use any number of nested rules as described in the following section.

Nested Rules

CSS selector { ZUSS content }

Example,

.bordered {
  &.float {
    float: left; 
  }
  .top {
    margin: 5px; 
  }
}

Outputs:

.bordered.float {
  float: left;  
}
.bordered .top {
  margin: 5px;
}

Function

Function Definition 1

@name (@argument-name: default-value, @argument-name: default-value): expression;

It defines a function with an expression. Example,

@darken(@color, @diff): @color * (1 - @diff);

Function Definition 2

@name (@argument-name: default-value, @argument-name: default-value): @import class-name;
@name (@argument-name: default-value, @argument-name: default-value): '@import class-name#method-name;

It defines a function imported from a Java method. Example,

@darken(@color, @diff): @import org.zkoss.zuss.Utils;

It assumes there is a Java class called org.zkoss.zuss.Utils, and it has a method called darken with the following signature:

public static String darken(String arg1, String arg2) {
   //...
}

First, it must return a string and the returned string will be outputed directly. Second, it could have any number of String-typed arguments. Third, it has to be a public static method.

If the function name is different from the method name, you could specify the method name at the end of the definition. Example,

@darken2(@color, @diff: 10%): @import org.zkoss.zuss.Utils#darken;

Function Usage

@name(expression 1, expression 2)

Example,

@nice_grey: #5B5B5B;
@darken(@color, @diff: 10%): @color * (1 - @diff);

div {
  color: @darken(@nice_grey);
}

Outputs:

div {
  color: #525252;
}

Expression in Style's Value

Expressions are allowed in the definition of variables, the definition of functions and the invocation of functions. However, to avoid the conflict with CSS's expression, expressions are not allowed in the value of a style. Rather, they are generated as CSS directly. For example, the CSS output will be exactly the same as ZUSS in the following example:

div {
  width: calc(2*1.5px + 1 + 1em);
}

If you'd like to evaluate it, you could use a built-in function called @eval and use the expression as the argument, such as

div {
  width: calc(@eval(2*1.5px + 1) + 1em);
}

The, it will generate the following CSS output:

div {
  width: calc(4px + 1em);
}

Include (not ready yet)

@include path ;

Example

@include another.zuss;

Conditional Content (not ready yet)

@if (expression) { ZUSS content }
@if (expression) {
  ZUSS content
} @elif (expression) {
  ZUSS content
} @else {
  ZUSS content
}

Example,

.box_shadow (@x: 0, @y: 0, @blur: 1px, @color: #000) {
  box-shadow: @arguments;
  @if (@gecko < 5) {
    -moz-box-shadow: @arguments;
  } @elif (@webkit) {
    -webkit-box-shadow: @arguments;
  }
}

Another example,

@if (@ie < 9) {
 .shadow {
	background: #888; zoom: 1; display: none;
	filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius=4, MakeShadow=true, ShadowOpacity=0.30)
 }
}

Version History

Last Update : 2011/11/11


Version Date Content
     



Last Update : 2011/11/11

Copyright © Potix Corporation. This article is licensed under GNU Free Documentation License.