em:
相对当前元素的相对长度单位。相对于当前对象内文本的字体尺寸。em的值并不是固定的,会继承父级元素的字体大小。如当前对行内文本的字体尺寸未被人为设置,则相对于浏览器的默认字体尺寸。
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.
rem:
相对html中根元素的字体尺寸的大小
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).
px:
像素是相对于显示器屏幕的分辨率的相对长度单位。
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
= 1/96th of 1in
.
fr:
一个自适应单位,fr单位被用于在一系列长度值中分配剩余空间,如果多个已指定了多个部分,则剩下的空间根据各自的数字按比例分配。
What we're doing here is setting a fixed width in pixels for the first column and then creating twelve separate columns which are set at one "fraction of the free space" (literally how the spec phrases it). But there's no crazy calculations or anything! It's super readable and if the width of that left nav changes then the width of our columns on the right will adjust themselves automatically.