📜  CSS-度量单位

📅  最后修改于: 2020-10-26 04:41:37             🧑  作者: Mango

在开始实际练习之前,我们想简要介绍一下CSS度量单位。 CSS支持多种度量,包括诸如英寸,厘米,点等的绝对单位,以及诸如百分比和em单位的相对度量。在样式规则中指定各种度量时,您需要这些值,例如border =“ 1px solid red”


Unit Description Example
% Defines a measurement as a percentage relative to another value, typically an enclosing element. p {font-size: 16pt; line-height: 125%;}
cm Defines a measurement in centimeters. div {margin-bottom: 2cm;}
em A relative measurement for the height of a font in em spaces. Because an em unit is equivalent to the size of a given font, if you assign a font to 12pt, each “em” unit would be 12pt; thus, 2em would be 24pt. p {letter-spacing: 7em;}
ex This value defines a measurement relative to a font’s x-height. The x-height is determined by the height of the font’s lowercase letter x. p {font-size: 24pt; line-height: 3ex;}
in Defines a measurement in inches. p {word-spacing: .15in;}
mm Defines a measurement in millimeters. p {word-spacing: 15mm;}
pc Defines a measurement in picas. A pica is equivalent to 12 points; thus, there are 6 picas per inch. p {font-size: 20pc;}
pt Defines a measurement in points. A point is defined as 1/72nd of an inch. body {font-size: 18pt;}
px Defines a measurement in screen pixels. p {padding: 25px;}