css - 是否可以在 HTML5 中省略占位符/水印?

标签 css html mobile-safari

我添加了这些 CSS。但我无法让占位符/水印带有省略号。不过它们确实有红色字体。

input::-webkit-input-placeholder {
    color:    red !important;
    max-width:  95% !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    overflow: hidden !important;
}

input:-moz-placeholder {
    color:    red !important;
    max-width:  95% !important;
    text-overflow: ellipsis !important;
    white-space: nowrap !important;
    overflow: hidden !important;
}

因为我在为移动设备工作,所以我希望它能在 Safari 中工作。

最佳答案

使用 :placeholder-shown 选择器效果很好,可以确保任何文本输入不会被隐藏。 Compatibility is pretty solid too .

input:placeholder-shown {
  text-overflow: ellipsis;
}
<input placeholder="A Long Placeholder to demonstrate"></input>

关于css - 是否可以在 HTML5 中省略占位符/水印?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10556365/

相关文章:

php - 如果值存在于 mysql 表中,则选中复选框

javascript - 同位素不居中

html - Angular Material : How to change top padding of mat-grid-tile

javascript - 如何检查子div的底部是否触及父底部

php - Yii2 可编辑图像

javascript - 使用 qtip 插件按钮进入工具提示不起作用

html - valign 中间不工作

css - sticky-top 不适用于 Angular8/safari

javascript - 在 iOS8 Safari 中,只读输入处理不正确

iphone - 从移动浏览器启动相机