Skip to content

10.px 和 em 的区别 #10

@webVueBlog

Description

@webVueBlog
Member

相同点:pxem 都是长度单位

异同点:px 的值是固定的,指定是多少就是多少,计算比较容易。

em 的值不是固定的,并且 em 会继承父级元素的字体大小。

浏览器的默认字体高都是 16px。所以未经调整的浏览器都符合: 1em=16px
那么 12px=0.75em, 10px=0.625em

Activity

webVueBlog

webVueBlog commented on Mar 11, 2020

@webVueBlog
MemberAuthor

Similarities: px and em are both units of length

Similarities and differences: the value of px is fixed.

The value of em is not fixed, and em inherits the font size of the parent element.

The default font height in the browser is 16px. So all untuned browsers are compliant: 1em=16px.
So 12px=0.75em, 10px=0.625em.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @webVueBlog

        Issue actions

          10.px 和 em 的区别 · Issue #10 · weekCodeing/interview-answe