ZK Class Concept"

From Documentation
Line 1: Line 1:
 
{{ZKStyleGuidePageHeader}}
 
{{ZKStyleGuidePageHeader}}
  
ZK Class (aka., zclass) is a naming pattern. It appends a particular pattern for particular user's activity, such as click, focus, mouse-over, mouse-out, and so on. For example, when a user moves the mouse over a button, additional CSS class will be added automatically to  the button. Since ZK Style Class of abutton is <tt>z-button</tt>, the CSS class will be <tt>z-button z-button-over</tt> when the mouse is over it. Similarly, if the button gains the focus, the CSS class will become <tt>z-button z-button-focus</tt>. Thus, we could customize a specific component for a particular scenario easily.
+
ZK Class (aka., zclass) is a naming pattern. It appends a class name with a particular pattern for a particular user's activity, such as click, focus, mouse-over, mouse-out, and so on. For example, when a user moves the mouse over a button, additional CSS class will be added automatically to  the button. The additional class is named by appending <tt>-over</tt> to the ZK Class.
  
ZK Class is also used to distinguish different molds of components, and even to provide totally different look for the same component in the same mold.  
+
For example, ZK Class of abutton is <tt>z-button</tt>, and then the additional CSS class will be <tt>z-button-over</tt>, when a user moves mouse over it. More precisely, the CSS class associated with the root DOM element of the component will become <tt>z-button z-button-over</tt>. Similarly, if the button gains the focus, the CSS class will become <tt>z-button z-button-focus</tt>. Thus, it is easier to customize the look for particular scenario, such as changing the look when a button gains the focus.
  
There are three different ways to change the style of ZK components:
+
The DOM structure of a component is sometimes complex. Some of the child DOM elements have to be styled with a proper CSS class. These classes are all named by using ZK Class as the prefix. For example, the DOM element at left-top corner is associated with a class named <tt>z-button-tl</tt>. Thus, ZK Class could be also used to distinguish different molds of components, and even to provide totally different look for the same component in the same mold.
 +
 
 +
In summary, there are three different ways to change the style of ZK components:
  
 
# Change sclass (<javadoc method="setSclass(java.lang.String)" type="interface">org.zkoss.zk.ui.Component</javadoc>)
 
# Change sclass (<javadoc method="setSclass(java.lang.String)" type="interface">org.zkoss.zk.ui.Component</javadoc>)
 +
#:Since zclass is not changed, the original look (i.e., CSS rules) will be applied too. It is useful to fine-tune a particular component
 
# Change zclass (<javadoc method="setZclass(java.lang.String)" type="interface">org.zkoss.zk.ui.Component</javadoc>)
 
# Change zclass (<javadoc method="setZclass(java.lang.String)" type="interface">org.zkoss.zk.ui.Component</javadoc>)
 +
#:Since zclass is changed, all child DOM elements will be associated with a different class. Thus, it won't inherit any of the original look, but it is useful if you'd like to design a complete different look
 
# Overwrite CSS rules (for the predefined CSS name)
 
# Overwrite CSS rules (for the predefined CSS name)
 +
#:You don't need to change sclass or zclass, if you'd like to change the look for every instance of the component. Rather, you just override the corresponding CSS rules (for the predefined CSS name, such as <tt>z-button-tl</tt>).
  
 
The relationship of sclass and zclass is shown below. The sclass, the red box below, will be added to the CSS class of the root DOM element of the component, while the zclass, the green box below, will be used as a prefix for the naming the CSS class of the child DOM elements.
 
The relationship of sclass and zclass is shown below. The sclass, the red box below, will be added to the CSS class of the root DOM element of the component, while the zclass, the green box below, will be used as a prefix for the naming the CSS class of the child DOM elements.

Revision as of 06:09, 8 April 2011

ZK Class Concept



ZK Class (aka., zclass) is a naming pattern. It appends a class name with a particular pattern for a particular user's activity, such as click, focus, mouse-over, mouse-out, and so on. For example, when a user moves the mouse over a button, additional CSS class will be added automatically to the button. The additional class is named by appending -over to the ZK Class.

For example, ZK Class of abutton is z-button, and then the additional CSS class will be z-button-over, when a user moves mouse over it. More precisely, the CSS class associated with the root DOM element of the component will become z-button z-button-over. Similarly, if the button gains the focus, the CSS class will become z-button z-button-focus. Thus, it is easier to customize the look for particular scenario, such as changing the look when a button gains the focus.

The DOM structure of a component is sometimes complex. Some of the child DOM elements have to be styled with a proper CSS class. These classes are all named by using ZK Class as the prefix. For example, the DOM element at left-top corner is associated with a class named z-button-tl. Thus, ZK Class could be also used to distinguish different molds of components, and even to provide totally different look for the same component in the same mold.

In summary, there are three different ways to change the style of ZK components:

  1. Change sclass (Component.setSclass(String))
    Since zclass is not changed, the original look (i.e., CSS rules) will be applied too. It is useful to fine-tune a particular component
  2. Change zclass (Component.setZclass(String))
    Since zclass is changed, all child DOM elements will be associated with a different class. Thus, it won't inherit any of the original look, but it is useful if you'd like to design a complete different look
  3. Overwrite CSS rules (for the predefined CSS name)
    You don't need to change sclass or zclass, if you'd like to change the look for every instance of the component. Rather, you just override the corresponding CSS rules (for the predefined CSS name, such as z-button-tl).

The relationship of sclass and zclass is shown below. The sclass, the red box below, will be added to the CSS class of the root DOM element of the component, while the zclass, the green box below, will be used as a prefix for the naming the CSS class of the child DOM elements.

For example, the following statement will assign the CSS class of the root DOM element with zk-button foo-pretty:

<button sclass="foo-pretty"/>





Last Update : 2011/04/08

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