css - 在输入占位符中为单个字母下划线

标签 css placeholder underline

可以将 CSS 样式应用于占位符,例如 Firefox:

::-moz-placeholder { text-decoration: underline; }

但是,我想做的是在占位符中加下划线,以提示用户按下热键(类似于文件菜单中的 Windows),例如制作 F First Name 中,下划线:

<input type='text' placeholder='First Name' />

有什么办法吗?

最佳答案

我认为您只能在谷歌浏览器中使用 CSS 来实现这一点。例如:

可以选择占位符的首字母

::-webkit-input-placeholder::first-letter {
  color: red;
  text-decoration:underline; 
}

结果:

enter image description here

在 Chrome(版本 39.0.2171.71)中使用 :first-letter 设置时,文本装饰不会呈现。所以我们可以用border-bottom来实现下划线。

::-webkit-input-placeholder::first-letter {
  color: red;
  border-bottom: 1px solid red;
}

结果:

enter image description here

更新:文本装饰在 Chrome 41.0.2235.0 Canary 上运行良好。

enter image description here

这是演示:http://codepen.io/MizR/pen/myeJZe

不幸的是,此解决方案不适用于 Firefox。 :(

更新 2: 不再有效。 :(

关于css - 在输入占位符中为单个字母下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27210066/

相关文章:

google-apps-script - 谷歌表格 setUnderline (offsetBegin, offsetEnd)

jquery - 悬停一个 DIV,给封闭的 DIV 一个阴影

html - <a name =""> 在 firefox 和移动浏览器上链接以上部分而不是内部

javascript - 按名称将占位符添加到输入字段

javascript - 使用 JS 获取正确的占位符颜色

html - CSS:为大下行字体制作厚 <a:hover> 下划线的正确方法

html - Safari 中的 CSS block 状圆 Angular

jQuery 在元素上添加样式 - 不可能在使用 CSS 后对其进行转换

css - Firefox 中搜索栏上的占位符文本未对齐

wpf - 如何在文本框中显示多个带颜色下划线的文本