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)).


MDN Reference

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)).


MDN Reference

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.


MDN Reference

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.


MDN Reference

pub fn cm(value: Int) -> Length

One centimeter. 1cm = 96px / 2.54.


MDN Reference

pub fn cm_(value: Float) -> Length

One centimeter. 1cm = 96px / 2.54.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

pub fn in(value: Int) -> Length

One inch. 1in = 2.54cm = 96px.


MDN Reference

pub fn in_(value: Float) -> Length

One inch. 1in = 2.54cm = 96px.


MDN Reference

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.


MDN Reference

pub fn mm(value: Int) -> Length

One millimeter. 1mm = 1cm / 10.


MDN Reference

pub fn mm_(value: Float) -> Length

One millimeter. 1mm = 1cm / 10.


MDN Reference

pub fn pc(value: Int) -> Length

One pica. 1pc = 12pt = 1in / 6.


MDN Reference

pub fn pc_(value: Float) -> Length

One pica. 1pc = 12pt = 1in / 6.


MDN Reference

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.


MDN Reference

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.


MDN Reference

pub fn pt(value: Int) -> Length

One point. 1pt = 1in / 72.


MDN Reference

pub fn pt_(value: Float) -> Length

One point. 1pt = 1in / 72.


MDN Reference

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.


MDN Reference

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.


MDN Reference

pub fn q(value: Int) -> Length

One quarter of a millimeter. 1Q = 1cm / 40.


MDN Reference

pub fn q_(value: Float) -> Length

One quarter of a millimeter. 1Q = 1cm / 40.


MDN Reference

pub fn rcap(value: Float) -> Length

Equal to the “cap height” (nominal height of capital letters) of the root element’s font.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

pub fn ric(value: Float) -> Length

Equal to the value of ic unit on the root element’s font.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

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.


MDN Reference

pub fn vmax(value: Int) -> Length

Represents in percentage the larget of vw and vh.


MDN Reference

pub fn vmax_(value: Float) -> Length

Represents in percentage the larget of vw and vh.


MDN Reference

pub fn vmin(value: Int) -> Length

Represents in percentage the smallest of vw and vh.


MDN Reference

pub fn vmin_(value: Float) -> Length

Represents in percentage the smallest of vw and vh.


MDN Reference

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.


MDN Reference

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.


MDN Reference

Search Document