html - Chrome 中的 CSS 输入高度

标签 html css google-chrome

如果我使用以下 CSS 创建一个 input

input {
  border: none;
  font-family: arial, sans-serif;
  font-size: 16px;
  line-height: 16px;
  padding: 0;
}

我预计 input 的高度为 16px,但 Chrome 开发者工具显示的高度为 18px。

Chrome Developer Tools calculated box model

在 Firefox 中,高度为 16px。

是什么导致 Chrome 中额外的 2px?

fiddle :https://jsfiddle.net/fh7upk0n/

我知道如果我想要一个固定的高度我必须使用高度,但我想知道 2px 是从哪里来的。

最佳答案

你应该使用height而不是line-height

height- the vertical measurement of the container

line-height- the distance from the top of the first line of text to the top of the second

关于html - Chrome 中的 CSS 输入高度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42888544/

相关文章:

html - 如何使 CSS 背景响应特定尺寸

html - Chrome 不尊重零宽度连接器

html - 在 IE8 中悬停时防止跳动的字段集

html - 跨多个子目录使用 HTML 模板

javascript - 制作一个 div 滚动以显示位于下方的主要内容

css - 是否可以只针对 Chrome,而不是所有支持 Webkit 的浏览器?

google-chrome - 为什么我收到无法调用未定义的方法 'addListener'?

html - 如何使输入字段不可选择

javascript - 人力车通过自定义按钮删除系列(切换操作)

javascript - Jquery加载的php脚本如何设置CSS