当前位置:   article > 正文

CSS Units_relative units css

relative units css

CSS has several different units for expressing a length. Many CSS properties take "length" values, such as width, margin, padding, font-size, border-width, etc. 

CSS 有不同的单位用来描述长度

A whitespace cannot appear between the number and the unit. 

表示长度的数字和单位之间不能有空格

However, if the value is 0, the unit can be omitted

如果长度值为 0, 则单位缺省

For some CSS properties, negative lengths are allowed.  一些CSS属性允许长度是负值

There are two types of length units: relative and absolute.

有两种类型的长度,相对的和绝对的。


Relative Length

specify a length relative to another length property.

相对长度,定义了一个相对于另一个长度属性的长度。

枚举:em, ex, ch, rem, vw, vh, vmin, vmax, %, px

px

pixels (1px = 1/96th of 1in)

em

Relative to the font-size of the element (2em means 2 times the size of the current font)

长度是相对于当前字体大小,注意:字体是可继承的,当前字体大小可能有变。

rem

Relative to font-size of the root element

长度是相对于根元素 ( <html>)字体大小而言。因为根元素字体通常定义一次不再改变,使用rem作为长度单位的 CSS 属性因而稳定且consistent。

Bootstrap设定html元素的fontsize是10px

Tip: The em and rem units are practical in creating perfectly scalable layout!

这两种长度单位常用于创建完美的可放大的布局。


Absolute Lengths

The absolute length units are fixed and a length expressed in any of these will appear as exactly that size.  

使用绝对长度单位的长度是固定的

They are not recommended for use on screen, because screen sizes vary so much. However, they can be used if the output medium is known, such as for print layout.

因为屏幕的多样性,不建议在 screen 上使用这种单位设定长度。在打印布局时可以使用。

枚举: cm, mm, in, pt, pc

in

inches (1in = 96px = 2.54cm)

pt

points (1pt = 1/72 of 1in)


声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/很楠不爱3/article/detail/327594
推荐阅读
相关标签
  

闽ICP备14008679号