The pseudo-algorithm below determines the used values for
'column-count' (N) and 'column-width' (W). There are two other
variables There is one other variable in the
pseudo-algorithm: U is the used width of the
multi-column element.
Note: The used width U of the multi-column element may depend on the element's contents, in which case it also depends on the computed values of the 'column-count' and 'column-width' properties. This specification does not define how U is calculated. Another module (probably the Basic Box Model [[CSS3BOX]] or the Intrinsic & Extrinsic Sizing Module [[CSS3-SIZING]]) is expected to define this.
available-width
: if the used width of the
multi-column element has not been determined when the 'column-count'
and 'column-width' must be determined (e.g., if it is floating with a
'width' of 'auto' as per CSS 2.1 section 10.3.5) this variable is
unknown
, otherwise it is the same as the used width of
the multi-column element. In vertical text, the used height replaces
used width in this calculation.shrink-to-fit
: this variable represents the result of
a shrink-to-fit computation. CSS does not define the exact
algorithm. Two assumptions are being made by the pseudo-algorithm:
The floor(X)
function
rounds a number to the next smaller integer returns
the largest integer Y ≤ X.
(01) if ((column-width = auto) and (column-count = auto)) then (02)exit;/* not a multicol element */(03) if ((available-width = unknown) and (column-count = auto)) then (04) exit; /* no columns */ (05) if (available-width = unknown) and (column-count != auto) and (column-width != auto) then (06) N := column-count; (07) W := column-width; (08) exit; (09) if (available-width = unknown) then (10) available-width := shrink-to-fit;(11) if (column-width = auto) and (column-count != auto) then (12) N := column-count; (13) W := max(0, (available-widthU - ((N - 1) * column-gap)) / N); (14)exit;(15) if (column-width != auto) and (column-count = auto) then (16) N := max(1, floor((available-widthU + column-gap) / (column-width + column-gap))); (17) W := ((available-widthU + column-gap) / N) - column-gap; (18)exit;(19) if (column-width != auto) and (column-count != auto) then (20) N := min(column-count, floor((available-widthU + column-gap) / (column-width + column-gap))) (21) N := max(1, N); (22) W := ((available-widthU + column-gap) / N) - column-gap; (23)exit
In paged media, user agents may perform this calculation on a per-page basis.
Note that, in most cases, only one of 'column-width' and
'column-count' affect the layout. If 'column-width' has a value other
than ''auto'', 'column-count' indicates the maximum number of columns.
However, both 'column-width' and 'column-count' are honored when the
width of the element has not been determined depends
on its contents. This can, e.g., be the case for table cells and
floats.