css - 当使用 box-sizing :border-box in *Chrome*, 时,为什么 <input type ="text"> 与 <input type ="password"> 呈现不同

标签 css google-chrome

查看应用了相同 CSS 样式的 2 个输入,第一个是 type="text",第二个是 type="password" Screenshot showing input padding & height

两个输入的总高度(padding-top + content-height + padding bottom)小于声明的高度(30px),但是,文本输入使其内容可见。密码输入看起来是空的(并且光标不显示)。

我已经修复了 padding-top/-bottom 值,但那是在尝试调试为什么密码字段不“工作”的长期斗争之后。我只是想知道为什么行为不同

链接到 JS Fiddle ,或查看 HTML + CSS:

HTML:

<input type="text" value="hello"/>
<input type="password" value="hello"/>

CSS:

* {
    box-sizing: border-box;
}

textarea, input[type="text"], input[type="password"], input[type="datetime"],       input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"], input[type="search"], input[type="tel"], input[type="color"] {
    height: 30px;
    line-height:30px;
    display:inline-block;
    vertical-align: middle;
}
textarea, input[type="text"], input[type="password"], input[type="datetime"], input[type="datetime-local"], input[type="date"], input[type="month"], input[type="time"], input[type="week"], input[type="number"], input[type="email"], input[type="url"],     input[type="search"], input[type="tel"], input[type="color"] {
  padding: 16px 11px 16px 11px !important;
  font-size:14px !important;
  color:#333 !important;
  border: 1px solid black !important;
}

最佳答案

这是您的 CSS 的缺陷。

根据你的CSS,<input>的内容高度是30px - 16px - 16px - 1px - 1px = -4px。因此,没有显示内容的空间。

关于css - 当使用 box-sizing :border-box in *Chrome*, 时,为什么 &lt;input type ="text"> 与 &lt;input type ="password"> 呈现不同,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24210428/

相关文章:

css - 当手机更改为横向时,响应式网站菜单按钮消失

html - 我的 html 表单和元素重叠并使我的页面不直观

javascript - 打开新标签页时检查弹出窗口拦截器是否启用

html - 如何创建指向共享网络目录或文件的超链接?

html - 目标 safari css,但不是 chrome

javascript - Chrome 跨域 PATCH 请求不起作用

javascript - div问题的奇偶选择器

html - 使用宽度 ="200"有什么区别;和宽度 ="200px"?

javascript - Chrome 扩展 - html 未定义

Javascript Onclick 按钮 - 取消第二次点击时执行的操作