sketch/css/length
Length
defines a CSS Unit.
It can be either px
, pt
, vh
, vw
, em
, rem
, lh
, rlh
, ch
, %
.
To instanciate a Length
, use the corresponding functions. Every unit exposes
two functions: the Int function (like px(0)
) and the Float version suffixed
by an underscore (like px_(0.0)
).
Types
Length
defines a CSS Unit.
It can be either px
, pt
, vh
, vw
, em
, rem
, lh
, rlh
, ch
, %
.
To instanciate a Length
, use the corresponding functions. Every unit exposes
two functions: the Int function (like px(0)
) and the Float version suffixed
by an underscore (like px_(0.0)
).
pub opaque type Length
Functions
pub fn cap(value: Float) -> Length
Represents the “cap height” (nominal height of capital letters) of the element’s font.
pub fn ch(value: Float) -> Length
Represents the width or, more precisely, the
advance measure
of the glyph 0
(zero, the Unicode character U+0030) in the element’s font
.
In cases where determining the measure of the 0
glyph is impossible or
impractical, it must be assumed to be 0.5em
wide by 1em
tall.
pub fn cqb(value: Int) -> Length
Represents a percentage of the block size of the query container. 1cqb
is
1% of the query container’s block size. For example, if the query container’s
block size is 300px
, then a value of 10cqb
on a property will be 30px
.
pub fn cqb_(value: Float) -> Length
Represents a percentage of the block size of the query container. 1cqb
is
1% of the query container’s block size. For example, if the query container’s
block size is 300px
, then a value of 10cqb
on a property will be 30px
.
pub fn cqh(value: Int) -> Length
Represents a percentage of the height of the viewport’s initial
containing block.
1vh
is 1% of the viewport height. For example, if the query container’s height is
300px
, then a value of 70vh
on a property will be 210px
.
pub fn cqh_(value: Float) -> Length
Represents a percentage of the height of the query container.
1cqh
is 1% of the query container’s height. For example, if the query container’s height is
300px
, then a value of 70vh
on a property will be 210px
.
pub fn cqi(value: Int) -> Length
Represents a percentage of the inline size of the query container. 1cqi
is 1% of the query container’s inline size. For example, if the query container’s
inline size is 800px
, then a value of 50cqi
on a property will be 400px
.
pub fn cqi_(value: Float) -> Length
Represents a percentage of the inline size of the query container. 1cqi
is 1% of the query container’s inline size. For example, if the query container’s
inline size is 800px
, then a value of 50cqi
on a property will be 400px
.
pub fn cqmax(value: Int) -> Length
Represents a percentage of the larger value of either the query container’s
inline size or block size. 1cqmax
is 1% of the larger value of either the
query container’s inline size or block size. For example, if the query
container’s inline size is 800px
and its block size is 300px
, then a
value of 50cqmax
on a property will be 400px
.
pub fn cqmax_(value: Float) -> Length
Represents a percentage of the larger value of either the query container’s
inline size or block size. 1cqmax
is 1% of the larger value of either the
query container’s inline size or block size. For example, if the query
container’s inline size is 800px
and its block size is 300px
, then a
value of 50cqmax
on a property will be 400px
.
pub fn cqmin(value: Int) -> Length
Represents a percentage of the smaller value of either the query container’s
inline size or block size. 1cqmin
is 1% of the smaller value of either the
query container’s inline size or block size. For example, if the query
container’s inline size is 800px
and its block size is 300px
, then a
value of 50cqmin
on a property will be 150px
.
pub fn cqmin_(value: Float) -> Length
Represents a percentage of the smaller value of either the query container’s
inline size or block size. 1cqmin
is 1% of the smaller value of either the
query container’s inline size or block size. For example, if the query
container’s inline size is 800px
and its block size is 300px
, then a
value of 50cqmin
on a property will be 150px
.
pub fn cqw(value: Int) -> Length
Represents a percentage of the width of the query container.
1cqw
is 1% of the query container’s width. For example, if the query container’s width is
800px
, then a value of 50vh
on a property will be 400px
.
pub fn cqw_(value: Float) -> Length
Represents a percentage of the width of the query container.
1cqw
is 1% of the query container’s width. For example, if the query container’s width is
800px
, then a value of 50vh
on a property will be 400px
.
pub fn em(value: Float) -> Length
Represents the calculated font-size
of the element. If used on the
font-size
property itself, it represents the inherited font-size of
the element.
pub fn ex(value: Float) -> Length
Represents the x-height of the
element’s font
. In fonts with the x
letter, this is generally the height
of lowercase letters in the font; 1ex ≈ 0.5em
in many fonts.
pub fn ic(value: Float) -> Length
Equal to the used advance measure of the “水” glyph (CJK water ideograph, U+6C34), found in the font used to render it.
pub fn lh(value: Float) -> Length
Equal to the computed value of the line-height
property of the element on
which it is used, converted to an absolute length. This unit enables length
calculations based on the theoretical size of an ideal empty line. However,
the size of actual line boxes may differ based on their content.
pub fn percent(value: Int) -> Length
Represents a percentage value. It is often used to define a size as relative
to an element’s parent object. Numerous properties can use percentages,
such as width
, height
, margin
, padding
, and font-size
.
pub fn percent_(value: Float) -> Length
Represents a percentage value. It is often used to define a size as relative
to an element’s parent object. Numerous properties can use percentages,
such as width
, height
, margin
, padding
, and font-size
.
pub fn px(value: Int) -> Length
One pixel. For screen displays, it traditionally represents one device pixel
(dot). However, for printers and high-resolution screens, one CSS pixel
implies multiple device pixels. 1px = 1in / 96
.
pub fn px_(value: Float) -> Length
One pixel. For screen displays, it traditionally represents one device pixel
(dot). However, for printers and high-resolution screens, one CSS pixel
implies multiple device pixels. 1px = 1in / 96
.
pub fn rcap(value: Float) -> Length
Equal to the “cap height” (nominal height of capital letters) of the root
element’s font
.
pub fn rch(value: Float) -> Length
Equal to the width or the
advance measure
of the glyph 0
(zero, the Unicode character U+0030) in the root
element’s font
.
pub fn rem(value: Float) -> Length
Represents the font-size
of the root element (typically <html>
). When
used within the root element font-size
, it represents its initial value.
A common browser default is 16px
, but user-defined preferences may
modify this.
pub fn rex(value: Float) -> Length
Represents the x-height of the
root element’s font
. In fonts with the x
letter, this is generally the height
of lowercase letters in the font; 1ex ≈ 0.5em
in many fonts.
pub fn ric(value: Float) -> Length
pub fn rlh(value: Float) -> Length
Equal to the value of lh
unit on the root element’s font. This unit enables
length calculations based on the theoretical size of an ideal empty line.
However, the size of actual line boxes may differ based on their content.
pub fn vb(value: Int) -> Length
Represents the percentage of the size of the initial containing block, in the direction of the root element’s block axis.
pub fn vb_(value: Float) -> Length
Represents the percentage of the size of the initial containing block, in the direction of the root element’s block axis.
pub fn vh(value: Int) -> Length
Represents a percentage of the height of the viewport’s initial
containing block.
1cqh
is 1% of the query container’s height. For example, if the viewport height is
300px
, then a value of 70vh
on a property will be 210px
.
pub fn vh_(value: Float) -> Length
Represents a percentage of the height of the viewport’s initial
containing block.
1cqh
is 1% of the query container’s height. For example, if the viewport height is
300px
, then a value of 70vh
on a property will be 210px
.
pub fn vi(value: Int) -> Length
Represents the percentage of the size of the initial containing block, in the direction of the root element’s inline axis.
pub fn vi_(value: Float) -> Length
Represents the percentage of the size of the initial containing block, in the direction of the root element’s inline axis.
pub fn vmax(value: Int) -> Length
pub fn vmax_(value: Float) -> Length
pub fn vmin(value: Int) -> Length
pub fn vmin_(value: Float) -> Length
pub fn vw(value: Int) -> Length
Represents a percentage of the width of the viewport’s initial
containing block.
1vw
is 1% of the viewport width. For example, if the viewport width is
800px
, then a value of 50vh
on a property will be 400px
.
pub fn vw_(value: Float) -> Length
Represents a percentage of the width of the viewport’s initial
containing block.
1vw
is 1% of the viewport width. For example, if the viewport width is
800px
, then a value of 50vh
on a property will be 400px
.