Hflex and Vflex"

From Documentation
Line 54: Line 54:
  
 
=Limitations=
 
=Limitations=
* [[ZK Component Reference/Containers/Span|Span]] ignores the width and height, so hflex and vflex has no effect on them (unless you specify [http://www.quirksmode.org/css/display.html display:block] -- but it makes it div eventually).
+
 
 +
==Spna Ignores Width and Height ==
 +
 
 +
[[ZK Component Reference/Containers/Span|Span]] ignores the width and height, so hflex and vflex has no effect on them (unless you specify [http://www.quirksmode.org/css/display.html display:block] -- but it makes it div eventually).
  
 
<source lang="xml">
 
<source lang="xml">
Line 79: Line 82:
 
</source>
 
</source>
  
* Hflex will be wrong if a component is aligned in the same ''row'' with its siblings. For example,
+
== Hflex Must Align Correctly ==
 +
 
 +
Hflex will be wrong if a component is aligned in the same ''row'' with its siblings. For example,
  
 
<source lang="xml">
 
<source lang="xml">
Line 91: Line 96:
  
 
[[Image:DrFlexErr2.png‎]]
 
[[Image:DrFlexErr2.png‎]]
 +
 +
This limitation can be solved by use of [[ZK Component Reference/Layouts/Hlayout|hlayout]] and [[ZK Component Reference/Containers/Div|div]] as show in the previous subsection.
  
 
=Version History=
 
=Version History=

Revision as of 06:48, 22 December 2010



Hflex (HtmlBasedComponent.setHflex(String)) and vflex (HtmlBasedComponent.setVflex(String)) indicate the flexibility of the component, which indicates how an component's parent distributes remaining empty space among its children. Hflex controls the flexibility in the horizontal direction, while vflex the vertical direction.

Flexible components grow and shrink to fit their given space. Components with larger flex values will be made larger than components with lower flex values, at the ratio determined by the two components. The actual value is not relevant unless there are other flexible components within the same container. Once the default sizes of components in a box are calculated, the remaining space in the box is divided among the flexible components, according to their flex ratios. Specifying a flex value of 0 has the same effect as leaving the flex attribute out entirely.

Fit-the-Rest Flexibility

The simplest use of flex is to have one component to take the rest of the space of its parent (or the page, if it is the root component). For example,

<zk>
  <datebox/>
  <div vflex="1" style="background: yellow"/>
</zk>

And, the result

DrFlex1.png

Notice that, if the parent has no predefined height (i.e., its height is decided by this children), the flexible component won't take any space. For example, the inner div (with vflex) takes no space in the following example:

<div>
  <datebox/>
  <div vflex="1" style="background: yellow"/><!-- height will be zero since height not specified in parent div -->
</div>

To solve it, you have to specify the height in the outer div, such as <div height="100%">, <div height="200px">, or <div vflex="1">.

Proportional Flexibility

The absolute value of the vflex/hflex is not that important. It is used to determine the proportion among flexible components. That is, you can give different integer to different child components so they will take space proportionally per the given vflex/hflex value. For example,

<div width="200px" height="50px">
	<div style="background: blue" vflex="1" hflex="1"/>
	<div style="background: yellow" vflex="2" hflex="1"/>
</div>

And, the result is

DrFlex2.png

Minimum Flexibility

Grid's Column and Flexibility

Flexibility versus Percentage

Limitations

Spna Ignores Width and Height

Span ignores the width and height, so hflex and vflex has no effect on them (unless you specify display:block -- but it makes it div eventually).

<!-- this example does not work -->
<div width="200px">
	<span style="background: blue" hflex="1">1</span>
	<span style="background: yellow" hflex="2">2</span>
</div>

And, the result is as follows - the width has no effect:

DrFlexErr1.png

This limitation can be solved by use of hlayout and div as follows.

<!-- this is correct -->
<hlayout width="200px">
	<div style="background: blue" hflex="1" vflex="1">1</div>
	<div style="background: yellow" hflex="2" vflex="1">2</div>
</hlayout>

Hflex Must Align Correctly

Hflex will be wrong if a component is aligned in the same row with its siblings. For example,

<div width="200px">
  <div style="background: blue" hflex="1">1</div><!-- not work since it won't be aligned with sibling div -->
  <div style="background: yellow" hflex="2">2</div>
</div>

As shown below, the second div is not aligned vertically with the first div, so is the width not as expected:

DrFlexErr2.png

This limitation can be solved by use of hlayout and div as show in the previous subsection.

Version History

Last Update : 2010/12/22


Version Date Content
     



Last Update : 2010/12/22

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