为什么< button>标记与< div>的处理方式不同做?

编程入门 行业动态 更新时间:2024-10-10 14:23:33
本文介绍了为什么< button>标记与< div>的处理方式不同做?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我注意到< button>标签似乎是从除字体大小以外的其他方面缩放em单位. < div>标签没有表现出相同的行为. 最新版本的chrome,firefox&即.

I've noticed that <button> tags seem to be scaling em units from something other than the font-size. <div> tags aren't exhibiting this same behaviour. This happens across the latest versions of chrome, firefox & ie.

它们的样式都如下:

button, div { width: 3rem; height: 3em; }

有关示例,请参见此小提琴.

如果我将div和按钮的大小都设置为3rem的宽度和3em的高度,则我希望它们是正方形的,除非存在影响其中一个或祖先的字体大小样式.唯一的字体大小在< body>上.标签,但是发生的是div是正方形,但是按钮的高度小于宽度.

If I size a div and a button both with a width of 3rem and height of 3em, I would expect them to be square, unless there is a font-size style affecting one of them, or an ancestor. The only font-size is on the <body> tag, but what happens is that the div is square, but the button has a smaller height than its width.

如果我检查Chrome中的按钮,则表示它从< body>继承了1em字体大小.标签,但是当我将其字体大小显式设置为1em时,该问题已解决(请参见小提琴).

If I inspect the button in chrome, it says that it inherits the 1em font-size from the <body> tag, and yet the problem is fixed when I set its font size to 1em explictly (see fiddle).

有人可以向我解释这里发生了什么吗?感觉好像我缺少明显的东西.

Can anyone explain to me what's happening here? It feels like I'm missing something obvious.

推荐答案

似乎您的HTML按钮没有继承<body>的字体大小.我相信许多表单元素的行为方式都是这样(至少在某些浏览器中如此),尽管我没有任何文档.

It seems that your HTML button was not inheriting font size from <body>. I believe many form elements behave this way (at least in some browsers), though I have no documentation.

通过添加以下内容,我获得了成功

I had success by adding:

button { font-size:inherit; }

工作示例

更多推荐

为什么&lt; button&gt;标记与&lt; div&gt;的处理方式不同做?

本文发布于:2023-11-16 11:06:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1603716.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:标记   方式   lt   amp   button

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!