简体   繁体   中英

Are rems and ems equivalent when used at root level?

From this answer I see what's the definition of rem in the spec:

rem unit

Equal to the computed value of font-size on the root element. When specified in the font-size property of the root element, or in a document with no root element, 1rem is equal to the initial value of the font-size property.

And the definition of em is:

em unit

Equal to the computed value of the font-size property of the element on which it is used.

To me this implies that 1em == 1rem by definition when used at :root .

Am I correct?

Yes

 :root { font-size:40px; border-top: 1rem solid red; border-bottom:1em solid green; }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM