为什么em不同于px上的按钮? [英] Why is em different than px on a button?

查看:151
本文介绍了为什么em不同于px上的按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个带有按钮html标签的按钮。现在我试图使高度和宽度在em。我知道16px等于1em。这个规则适用于我迄今为止除了按钮以外的所有东西。如果我想要按钮的高度为45px,按钮将高45px。如果我想改变45px到em,这将是2.8125em。这会短很多。要使它接近45px与em它实际上将在3.5em左右,在px实际上是56px。这是为什么?这是浏览器的问题吗?我正在使用Safari。

I created a button with a button html tag. Now I'm trying to make the height and width in em. I know 16px is equal to 1em. That rule applies to everything I've seen so far except the button. If I wanted the button height to be 45px, the button will be 45px high. If I wanted to change the 45px to em, which would be 2.8125em. It would be a lot shorter. To make it close to 45px with em it would actually be around 3.5em which in px is actually 56px. Why is that? Is that a browser issue? I'm using Safari by the way.

推荐答案

em 到所讨论的元素的字体大小。如果您的按钮的字体大小不同于 16px ,则 em 也会有所不同。

em is equal to the font-size of the element in question. If your button has a font-size different from 16px, then em will be different as well.

您一直在查看的所有元素的字体大小必须设置为16px。这不奇怪,因为它是许多浏览器的默认值。

All of the elements you've been looking at must have their font-size set to 16px. This isn't too surprising, as it's the default for many browsers.

这篇关于为什么em不同于px上的按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆