Language"

From Documentation
m (correct highlight (via JWB))
 
(36 intermediate revisions by 2 users not shown)
Line 1: Line 1:
ZESS, inspired by [http://lesscss.org LESS], is an extension to CSS. It is compatible with CSS, while allows to use variables, mixins, nested rules, expressions, and Java methods with existing CSS syntax.
+
{{ZUSSReferencePageHeader}}
 +
 
 +
{{Deprecated|url=https://www.zkoss.org/wiki/ZK_Developer%27s_Reference/Theming_and_Styling}}
 +
 
 +
__TOC__
  
 
=Variables=
 
=Variables=
Line 5: Line 9:
 
==Variable Definition==
 
==Variable Definition==
 
  @''name'': ''value'';
 
  @''name'': ''value'';
  @''name'': (''expression'');
+
  @''name'': ''expression'';
  
 
Example,
 
Example,
  
 
<source lang="CSS">
 
<source lang="CSS">
@nice_blue: #5B83AD;
+
@nice-blue: #5B83AD;
@light_blue: (@nice_blue + #111);
+
@light-blue: @nice-blue + #111;
 
</source>
 
</source>
  
The name must be composed of letters, numbers, and the underscore. The name may only begin with a letter and the underscore.
+
The name must be composed of letters, numbers, the underscore (_) and the dash (-).
  
 
==Variable Usage==
 
==Variable Usage==
Line 21: Line 25:
 
Example,
 
Example,
 
<source lang="CSS">
 
<source lang="CSS">
@nice_blue: #5B83AD;
+
@nice-blue: #5B83AD;
@light_blue: (@nice_blue + #111);
+
@light-blue: @nice-blue + #111;
 +
@dark-orange: orange - #010203; /*orange is a standard color.*/
  
div.hilite { color: @nice_blue;}
+
div.hilite { color: @light-blue;}
 +
div.hilite2 { color: @dark-orange;}
 
</source>
 
</source>
  
Line 31: Line 37:
 
<source lang="CSS">
 
<source lang="CSS">
 
div.hilite { color:  #6c94be;}
 
div.hilite { color:  #6c94be;}
 +
div.hilite2 { color: #fea300;}
 +
</source>
 +
 +
=Nested Rules=
 +
 +
''CSS3 selector'' { ''ZUSS content'' }
 +
 +
Example,
 +
 +
<source lang="CSS">
 +
.bordered {
 +
  &.float {
 +
    float: left;
 +
  }
 +
  .top {
 +
    margin: 5px;
 +
  }
 +
}
 +
</source>
 +
 +
Outputs:
 +
 +
<source lang="CSS">
 +
.bordered.float {
 +
  float: left; 
 +
}
 +
.bordered .top {
 +
  margin: 5px;
 +
}
 +
</source>
 +
 +
As shown, if the first character of the nested rule is '&amp;', the CSS3 selector will be concatenated directly with a white space.
 +
 +
==Nested Rules with @media==
 +
 +
[http://www.w3.org/TR/css3-mediaqueries/ The media queiries] (@media) can be nested with rules too. For example,
 +
 +
<source lang="CSS">
 +
div {
 +
@media print {
 +
span { color: orange;}
 +
}
 +
border: 1px solid blue;
 +
}
 +
</source>
 +
 +
Outputs:
 +
 +
<source lang="CSS">
 +
@media print {
 +
  div span {
 +
    color: orange;
 +
  }
 +
}
 +
div {
 +
  border: 1px solid blue;
 +
}
 
</source>
 
</source>
  
Line 36: Line 99:
 
==Mixin Definition==
 
==Mixin Definition==
 
  @''name'' (@''argument-name'': ''default-value'', @''argument-name'': ''default-value'') {
 
  @''name'' (@''argument-name'': ''default-value'', @''argument-name'': ''default-value'') {
   ''ZESS content''
+
   ''ZUSS content''
 
  }
 
  }
  
Line 52: Line 115:
  
 
==Mixin Usage==
 
==Mixin Usage==
  @''name''(''argument 1'', ''argument 2'');
+
  @''name''(''expression 1'', 'expression 2'');
  
 
Example,
 
Example,
Line 69: Line 132:
 
</source>
 
</source>
  
Outputs:
+
CSS equivalent:
  
 
<source lang="CSS">
 
<source lang="CSS">
Line 80: Line 143:
 
</source>
 
</source>
  
=Nested Rules=
+
Here is an example: a mixin with nested rules:
 
 
Example,
 
 
 
 
<source lang="CSS">
 
<source lang="CSS">
.bordered {
+
@border_radious(@radius: 4px, @color: orange) {
   &.float {
+
   border-radius: @radius;
    float: left;  
+
   div.hilite {
   }
+
     color: @color;
  .top {
 
     margin: 5px;  
 
 
   }
 
   }
 
}
 
}
</source>
 
  
Outputs:
+
div.rounded {
 
+
   @border_radious();
<source lang="CSS">
 
.bordered.float {
 
   float: left;
 
 
}
 
}
.bordered .top {
+
button.rounded {
   margin: 5px;
+
   @border_radious(3px, blue);
 
}
 
}
 
</source>
 
</source>
  
=Conditional Content=
+
Then, CSS equivalent:
(''condition'') { ''ZESS content'' }
 
 
 
Example,
 
  
 
<source lang="CSS">
 
<source lang="CSS">
.box_shadow (@x: 0, @y: 0, @blur: 1px, @color: #000) {
+
div.rounded {
   box-shadow: @arguments;
+
  border-radius: 4px
   (@gecko < 5) {-moz-box-shadow: @arguments);}
+
}
   (@webkit) {-webkit-box-shadow: @arguments);}
+
div.rounded div.hilite {
 +
   color: orange;
 +
}
 +
button.rounded {
 +
   border-radius: 3px
 +
}
 +
button.rounded div.hilite {
 +
   color: blue;
 
}
 
}
 
</source>
 
</source>
  
Another example,
+
Here is a CSS 3 example:
  
 
<source lang="CSS">
 
<source lang="CSS">
(@ie < 9) {
+
@coloring(@c1: navy, @c2: green, @c3: maroon, @c4) {
.shadow {
+
p:nth-child(4n+1) { color: navy; }
background: #888; zoom: 1; display: none;
+
p:nth-child(4n+2) { color: green; }
filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius=4, MakeShadow=true, ShadowOpacity=0.30)
+
p:nth-child(4n+3) { color: maroon; }
}
+
p:nth-child(4n+4) { color: purple; }
 
}
 
}
 +
@coloring();
 
</source>
 
</source>
  
 
=Function=
 
=Function=
 
==Function Definition 1==
 
==Function Definition 1==
  @''name'' (@''argument-name'': ''default-value'', @''argument-name'': ''default-value''): (''expression'')
+
  @''name'' (@''argument-name'': ''default-value'', @''argument-name'': ''default-value''): ''expression'';
  
 
It defines a function with an expression.
 
It defines a function with an expression.
Line 138: Line 197:
  
 
<source lang="CSS">
 
<source lang="CSS">
@darken(@color, @diff): (@color * (1 - @diff))
+
@darken(@color, @diff): @color * (1 - @diff);
 
</source>
 
</source>
  
 
==Function Definition 2==
 
==Function Definition 2==
  @''name'' (@''argument-name'': ''default-value'', @''argument-name'': ''default-value''): ''class-name''
+
  @''name'' (@''argument-name'': ''default-value'', @''argument-name'': ''default-value''): @import ''class-name'';
  @''name'' (@''argument-name'': ''default-value'', @''argument-name'': ''default-value''): ''class-name'' # ''method-name
+
  @''name'' (@''argument-name'': ''default-value'', @''argument-name'': ''default-value''): '@import ''class-name''#''method-name'';
  
 
It defines a function imported from a Java method.
 
It defines a function imported from a Java method.
Line 149: Line 208:
  
 
<source lang="CSS">
 
<source lang="CSS">
@darken(@color, @diff): org.zkoss.zess.Utils
+
@darken(@color, @diff): @import org.zkoss.zuss.Utils;
 
</source>
 
</source>
  
It assumes there is a Java class called org.zkoss.zess.Utils, and it has a method
+
It assumes there is a Java class called org.zkoss.zuss.Utils, and it has a method
 
called darken with the following signature:
 
called darken with the following signature:
  
Line 168: Line 227:
  
 
<source lang="CSS">
 
<source lang="CSS">
@darken2(@color, @diff: 10%): org.zkoss.zess.Utils#darken
+
@darken2(@color, @diff: 10%): @import org.zkoss.zuss.Utils#darken;
 
</source>
 
</source>
  
 
==Function Usage==
 
==Function Usage==
  @''name''(''argument 1'', ''argument 2'')
+
  @''name''(''expression 1'', ''expression 2'')
  
 
Example,
 
Example,
 
<source lang="CSS">
 
<source lang="CSS">
 
@nice_grey: #5B5B5B;
 
@nice_grey: #5B5B5B;
 +
@darken(@color, @diff: 10%): @color * (1 - @diff);
  
 
div {
 
div {
Line 191: Line 251:
 
</source>
 
</source>
  
=Expressions=
+
==Expression in Style's Value==
(''expression'')
+
Expressions are allowed in [[#Variable Definition|the definition of variables]], [[#Function Definition 1|the definition of functions]] and [[#Function Usage|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:
  
Example
+
<source lang="CSS">
 +
div {
 +
  width: calc(2*1.5px + 1 + 1em);
 +
}
 +
</source>
 +
 
 +
If you'd like to evaluate it, you could use a built-in function called <code>@eval</code> and use the expression as the argument, such as
  
 
<source lang="CSS">
 
<source lang="CSS">
 
div {
 
div {
   color: (@darken(@nice_grey + #111))
+
   width: calc(@eval(2*1.5px + 1) + 1em);
 
}
 
}
 
</source>
 
</source>
  
The expression must be enclosed with parentheses, <tt>(</tt> and <tt>)</tt>. The supported operators include <tt>+</tt>, <tt>-</tt>, <tt>*</tt> and <tt>/</tt>.
+
The, it will generate the following CSS output:
 +
 
 +
<source lang="CSS">
 +
div {
 +
  width: calc(4px + 1em);
 +
}
 +
</source>
  
 
=Include=
 
=Include=
  @include ''path''
+
 
 +
  @include ''path'' ;
  
 
Example
 
Example
  
 
<source lang="CSS">
 
<source lang="CSS">
@include another.zess
+
@include another.zuss;
 +
</source>
 +
 
 +
=Conditional Content=
 +
 
 +
@if (''expression'') { ''ZUSS content'' }
 +
 
 +
@if (''expression'') {
 +
  ''ZUSS content''
 +
} @elif (''expression'') {
 +
  ''ZUSS content''
 +
} @else {
 +
  ''ZUSS content''
 +
}
 +
 
 +
Example,
 +
 
 +
<source lang="CSS">
 +
.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;
 +
  }
 +
}
 +
</source>
 +
 
 +
Another example,
 +
 
 +
<source lang="CSS">
 +
@if (@ie < 9) {
 +
.shadow {
 +
background: #888; zoom: 1; display: none;
 +
filter: progid:DXImageTransform.Microsoft.Blur(PixelRadius=4, MakeShadow=true, ShadowOpacity=0.30)
 +
}
 +
}
 
</source>
 
</source>
 +
 +
=Version History=
 +
{{LastUpdated}}
 +
{| border='1px' | width="100%"
 +
! Version !! Date !! Content
 +
|-
 +
| &nbsp;
 +
| &nbsp;
 +
| &nbsp;
 +
|}
 +
 +
{{ZUSSReferencePageFooter}}

Latest revision as of 13:28, 19 January 2022



Stop.png This article is out of date, please refer to https://www.zkoss.org/wiki/ZK_Developer%27s_Reference/Theming_and_Styling for more up to date information.

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;}

Nested Rules

CSS3 selector { ZUSS content }

Example,

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

Outputs:

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

As shown, if the first character of the nested rule is '&', the CSS3 selector will be concatenated directly with a white space.

Nested Rules with @media

The media queiries (@media) can be nested with rules too. For example,

div {
	@media print {
		span { color: orange;}
	}
	border: 1px solid blue;
}

Outputs:

@media print {
  div span {
    color: orange;
  }
}
div {
  border: 1px solid blue;
}

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);
}

CSS equivalent:

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

Here is an example: a mixin with nested rules:

@border_radious(@radius: 4px, @color: orange) {
  border-radius: @radius;
  div.hilite {
    color: @color;
  }
}

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

Then, CSS equivalent:

div.rounded {
  border-radius: 4px
}
div.rounded div.hilite {
  color: orange;
}
button.rounded {
  border-radius: 3px
}
button.rounded div.hilite {
  color: blue;
}

Here is a CSS 3 example:

@coloring(@c1: navy, @c2: green, @c3: maroon, @c4) {
	p:nth-child(4n+1) { color: navy; }
	p:nth-child(4n+2) { color: green; }
	p:nth-child(4n+3) { color: maroon; }
	p:nth-child(4n+4) { color: purple; }
}
@coloring();

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

@include path ;

Example

@include another.zuss;

Conditional Content

@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 : 2022/01/19


Version Date Content
     



Last Update : 2022/01/19

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