Units

Updated at:

This topic describes the numeric, time, length, and color units used in Ant Dynamic Cards.

Numeric units

Some card properties, such as flex and lines, require pure numeric values. Do not add units such as px or vw after these numbers.

For the value range and type of these numeric values, see the property definitions for each component in General styles. If you provide a non-numeric value, it defaults to 0.

Example:

lines:5;
flex:1;

Time units

Some card properties, such as animation-duration, require a time value. The card supports seconds (s) and milliseconds (ms) as time units.

Example:

animation-duration:2s;

Length units

You can use several different units to represent length in cards. A length consists of a number and a unit, with no space in between. Length units are divided into built-in and custom units.

Built-in units

Relative lengths

Relative length units specify a length relative to another length property. This makes them ideal for designs that need to adapt to different devices.

  • vw: Viewport width. 1 vw equals 1% of the viewport width.

  • %: A percentage of the viewport height or width.

Example:

font-size: 20vw;
background-size:50%;

Absolute lengths

Absolute length units are fixed values. They are not relative to other properties, and their physical size depends on the output medium rather than the environment, such as the monitor, resolution, or operating system.

  • px: Pixel (1 px = 1/96th of 1 in)

  • rpx: Calculated based on a 750 baseline, where 2 rpx = 1 px.

Example:

font-size: 17px;
line-height:40rpx;

Click detailLength.zip to download the complete sample code.

Color units

You can specify colors in cards in the following ways:

  • Hexadecimal

  • RGB color

  • Color name

Hexadecimal colors

You can specify a hexadecimal color in several ways:

  • #RRGGBB, where RR (red), GG (green), and BB (blue) are two-digit hexadecimal values from 00 to FF.

For example, the value #0000FF is rendered as blue because the blue component is set to its highest value (FF) and the other components are set to 00.

  • #RGB, where R (red), G (green), and B (blue) are single-digit hexadecimal values from 0 to F.

For example, the value #00F is rendered as blue because the blue component is set to its highest value (F) and the other components are set to 0.

  • 0xrrggbb, where rr (red), gg (green), and bb (blue) are two-digit hexadecimal values from 00 to ff.

For example, the value 0x0000ff is rendered as blue because the blue component is set to its highest value (ff) and the other components are set to 00.

Example:

background-color:#ff0000;
border-top-color:0x0000ff;
border-bottom-color:#00f;

RGB colors

You can specify an RGB color in several ways:

  • RGB(red, green, blue). Each parameter (red, green, and blue) defines the intensity of the color as an integer between 0 and 255. For example, the value RGB(0,0,255) is rendered as blue because the blue parameter is set to its highest value, 255, and the others are set to 0.

  • RGBA(red, green, blue, alpha). The alpha parameter is a number between 0.0 (fully transparent) and 1.0 (fully opaque). For example, the value RGBA(0,0,255,0.5) is rendered as a semi-transparent blue.

Example:

background-color:rgb(0,0,255);
border-color:rgba(255,0,0,0.5);

Color names

Cards support 147 defined color names, including 17 standard colors and 130 other colors. The following tables list all color names and their corresponding hexadecimal values.

Standard colors

Name

Hexadecimal

red

0xffff0000

blue

0xff0000ff

black

0xff000000

...

...

Others

Name

Hexadecimal

red

0xffff0000

blue

0xff0000ff

black

0xff000000

...

...

Example

background-color:red;
Note
  • Only the color formats described in this topic are supported.

  • If you use an unsupported color format, the color defaults to transparent, unless the component's style specifies a different default color.

Click detailColor.zip to download the complete sample code.

Appendix - Color value definitions

Name

Color value

red

0xffff0000

darkred

0xff8b0000

tan

0xffd2b48c

linen

0xfffaf0e6

sienna

0xffa0522d

indianred

0xffcd5c5c

teal

0xff008080

grey

0xff808080

green

0xff008000

gray

0xff808080

darkgrey

0xffa9a9a9

darkgreen

0xff006400

beige

0xfff5f5dc

orange

0xffffa500

darkgray

0xffa9a9a9

orangered

0xffff4500

khaki

0xfff0e68c

seagreen

0xff2e8b57

gold

0xffffd700

darkorange

0xffff8c00

darkkhaki

0xffbdb76b

indigo

0xff4b0082

goldenrod

0xffdaa520

maroon

0xff800000

gainsboro

0xffdcdcdc

lime

0xff00ff00

greenyellow

0xffadff2f

darkgoldenrod

0xffb8860b

slategrey

0xff708090

slategray

0xff708090

salmon

0xfffa8072

darkseagreen

0xff8fbc8f

seaShell

0xfffff5ee

darksalmon

0xffe9967a

tomato

0xffff6347

thistle

0xffd8bfd8

darkslategrey

0xff2f4f4f

cyan

0xff00ffff

forestgreen

0xff228b22

dimgrey

0xff696969

darkslategray

0xff2f4f4f

mistyrose

0xffffe4e1

dimgray

0xff696969

darkcyan

0xff008b8b

black

0xff000000

magenta

0xffff00ff

limegreen

0xff32cd32

coral

0xffff7f50

darkmagenta

0xff8b008b

azure

0xfff0ffff

blue

0xff0000ff

oldlace

0xfffdf5e6

cornsilk

0xfffff8dc

darkblue

0xff00008b

skyblue

0xff87ceeb

firebrick

0xffb22222

orchid

0xffda70d6

lightgrey

0xffd3d3d3

lightgreen

0xff90ee90

lightyellow

0xffffffe0

lightgray

0xffd3d3d3

darkorchid

0xff9932cc

royalblue

0xff4169e1

aqua

0xff00ffff

steelblue

0xff4682b4

bisque

0xffffe4c4

crimson

0xffdc143c

slateblue

0xff6a5acd

dodgerblue

0xff1e90ff

blanchedalmond

0xffffebcd

lightseagreen

0xff20b2aa

lightslategrey

0xff778899

lightslategray

0xff778899

brown

0xffa52a2a

lightsalmon

0xffffa07a

snow

0xfffffafa

lightcyan

0xffe0ffff

rosybrown

0xffbc8f8f

sandybrown

0xfff4a460

darkslateblue

0xff483d8b

yellow

0xffffff00

lightcoral

0xfff08080

mintcream

0xfff5fffa

aquamarine

0xff7fffd4

saddlebrown

0xff8b4513

honeydew

0xfff0fff0

pink

0xffffc0cb

lightblue

0xffadd8e6

cadetblue

0xff5f9ea0

wheat

0xfff5deb3

lawngreen

0xff7cfc00

white

0xffffffff

aliceblue

0xfff0f8ff

chocolate

0xffd2691e

yellowgreen

0xff9acd32

moccasin

0xffffe4b5

navy

0xff000080

chartreuse

0xff7fff00

ivory

0xfffffff0

palegreen

0xff98fb98

lavender

0xffe6e6fa

hotpink

0xffff69b4

olive

0xff808000

fuchsia

0xffff00ff

mediumseagreen

0xff3cb371

silver

0xffc0c0c0

olivedrab

0xff6b8e23

darkturquoise

0xff00ced1

turquoise

0xff40e0d0

violet

0xffee82ee

violetred

0xffd02090

darkviolet

0xff9400d3

palegoldenrod

0xffeee8aa

whitesmoke

0xfff5f5f5

springgreen

0xff00ff7f

burlywood

0xffdeb887

peru

0xffcd853f

floralwhite

0xfffffaf0

lightpink

0xffffb6c1

darkolivegreen

0xff556b2f

ghostwhite

0xfff8f8ff

mediumblue

0xff0000cd

mediumorchid

0xffba55d3

lightsteelblue

0xffb0c4de

lightslateblue

0xff8470ff

transparent

0x00000000

deepskyblue

0xff00bfff

lightskyblue

0xff87cefa

lightgoldenrodyellow

0xfffafad2

plum

0xffdda0dd

mediumaquamarine

0xff66cdaa

mediumslateblue

0xff7b68ee

blueviolet

0xff8a2be2

midnightblue

0xff191970

deeppink

0xffff1493

lemonchiffon

0xfffffacd

antiquewhite

0xfffaebd7

paleturquoise

0xffafeeee

powderblue

0xffb0e0e6

navajowhite

0xffffdead

mediumspringgreen

0xff00fa9a

cornflowerblue

0xff6495ed

palevioletred

0xffdb7093

mediumvioletred

0xffc71585

purple

0xff800080

rebeccapurple

0xff663399

lavenderblush

0xfffff0f5

mediumturquoise

0xff48d1cc

peachpuff

0xffffdab9

mediumpurple

0xff9370db

papayawhip

0xffffefd5