javascript - 无法在 OS X 的 Safari 中聚焦零尺寸输入

标签 javascript html css safari

如果我在 OS X 的 Safari 9.1.3 中将其设置为零大小,我将无法专注于输入。

function doFocus() {
  document.querySelector("#input").focus();
}
input[type="text"] {
  /* make input zero size */
  border: none;
  width: 0;
  padding: 0;

  border-bottom: 2px solid transparent;
  transition: width .2s;
}
input[type="text"]:focus {
  border-bottom-color: #999;
  width: 200px;
}
<input type="text" id="input" placeholder="(placeholder)" />
<button onClick="doFocus()">Focus</button>

转载于此:https://codepen.io/kevinptt/pen/baoOXB

最佳答案

@kevin Lin 我没有 iPhone,所以我没有测试过它,但我认为视觉隐藏输入对你有用。

.visuallyhidden { 
  position: absolute; 
  overflow: hidden; 
  clip: rect(0 0 0 0);
  height: 1px; width: 1px; 
  margin: -1px; padding: 0; border: 0; 
}


// add this class when input will get focus

.reset-visuallyhidden {
  position: static;
  overflow: auto;
  clip: none;
  height: auto;
  margin: 0;
  padding: var(--padding, 0);
  border: 0;
}

关于javascript - 无法在 OS X 的 Safari 中聚焦零尺寸输入,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48120437/

相关文章:

css - 将 child 移动到 parent 的左侧(外侧)

html - 为什么这些 div 需要边框才能正确呈现?

javascript - Angular ui-router向url添加哈希

javascript - 当我使用 JavaScript 和 jQuery 在输入框中键入内容时,在预览区域中显示颜色

html - 使用 flex 在输入表单中放置按钮

html - 突出显示选项标签内的部分文本

javascript - 单击时的过渡效果

javascript - Node js缓冲区添加NULL终止消息

javascript - 仅当窗口关闭时才触发 onbeforeunload (包括工作示例)

jquery - 在 jQuery Mobile 中如何删除弹出对话框中的关闭图标