【问题标题】:Why does input[type="text"] change size on focus?为什么 input[type="text"] 在焦点上改变大小?
【发布时间】:2015-03-07 18:22:12
【问题描述】:

假设我有意见。

html

<input type="text">

css:

input, input:focus {
  border: none;
  outline: solid 1px grey;
  box-shadow: none;
}

点击后,输入会改变大小。我该如何阻止这种情况?

http://codepen.io/mildrenben/pen/QwVvZK

【问题讨论】:

  • 不,它没有。 [火狐 36]

标签: html css input


【解决方案1】:

如果您在 Chrome 中查看,这是因为以下默认用户代理样式:

input:focus, textarea:focus,
keygen:focus, select:focus {
    outline-offset: -2px;
}

因此在关注元素时需要将outline-offset设置为0

Updated Example

input:focus {
  outline-offset: 0;
}

【讨论】:

  • 哇!你让我省了很多心。它几乎让我大吃一惊。非常感谢!
  • 注意:如果您将输入的高度设置为 vh 单位,则类似的效果也会出现在移动设备上,因为键盘会显示在视口上
猜你喜欢
  • 2013-06-28
  • 1970-01-01
  • 1970-01-01
  • 2015-12-14
  • 2011-04-09
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多