Table of Contents

Enum CssUnit

Namespace
Egami.Css
Assembly
Egami.Css.dll

CSS length units (CSS Values 4), plus None for a unitless number and Percent.

public enum CssUnit

Fields

Cap = 13

The font's cap height.

Ch = 15

The advance of the font's "0".

Cm = 3

Centimeters (96px / 2.54).

Dvh = 32

1% of the dynamic viewport height.

Dvw = 31

1% of the dynamic viewport width.

Em = 9

The element's font size.

[SuppressMessage("Naming", "CA1711", Justification = "The CSS unit's name.")] Ex = 11

The font's x-height.

Ic = 17

The advance of the font's "水" (CJK water ideograph).

In = 6

Inches (96px).

Lh = 19

The element's line height.

Lvh = 30

1% of the large viewport height.

Lvw = 29

1% of the large viewport width.

Mm = 4

Millimeters.

None = 0

A unitless number, such as SVG's user units or a line-height multiplier.

Pc = 8

Picas (12pt).

Percent = 1

A percentage of a reference length the property defines.

Pt = 7

Points (1/72 in).

Px = 2

CSS pixels.

Q = 5

Quarter-millimeters.

Rcap = 14

The root font's cap height.

Rch = 16

The advance of the root font's "0".

Rem = 10

The root element's font size.

Rex = 12

The root font's x-height.

Ric = 18

The root font's Ic.

Rlh = 20

The root element's line height.

Svh = 28

1% of the small viewport height.

Svw = 27

1% of the small viewport width.

Vb = 24

1% of the viewport size in the block axis.

Vh = 22

1% of the viewport height.

Vi = 23

1% of the viewport size in the inline axis.

Vmax = 26

The larger of Vw and Vh.

Vmin = 25

The smaller of Vw and Vh.

Vw = 21

1% of the viewport width.

Examples

bool isLength = CssLength.TryParse("1.5em", out CssLength length);       // (1.5, CssUnit.Em)
new CssLength(1, CssUnit.In).TryToPixels(out double px);  // 96
bool isAngle = CssAngle.TryParse("0.25turn", out CssAngle angle);        // 90 degrees
bool isUrl = CssUrl.TryParse("url('pattern.svg#dots')", out CssUrl url);

// calc(), min(), max() and clamp(): the consumer says what each unit is worth.
bool isCalc = CssCalc.TryParse("calc(100% - 2em)", out CssCalc? calc);
double width = calc!.Resolve(unit => unit switch
{
    CssUnit.Percent => 3,   // a percent of a 300px box
    CssUnit.Em => 16,
    CssUnit.Px => 1,
    _ => double.NaN,
});                                                       // 268