Skip to content

10.px 和 em 的区别 #10

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
webVueBlog opened this issue Mar 10, 2020 · 1 comment
Open

10.px 和 em 的区别 #10

webVueBlog opened this issue Mar 10, 2020 · 1 comment
Labels
HTML&CSS HTML&CSS

Comments

@webVueBlog
Copy link
Member

相同点:pxem 都是长度单位

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

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

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

@webVueBlog webVueBlog added the HTML&CSS HTML&CSS label Mar 10, 2020
@webVueBlog
Copy link
Member Author

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
Labels
HTML&CSS HTML&CSS
Projects
None yet
Development

No branches or pull requests

1 participant