【问题标题】:Keep input placeholder text visible after user input在用户输入后保持输入占位符文本可见
【发布时间】:2018-04-10 01:20:10
【问题描述】:

我想让占位符在输入字段中写入内容后保持可见。

重要: 我不想使用任何其他元素来“解决”这个问题,我只想使用输入字段。请只使用 CSS,不要使用 JS 或 jQuery。

【问题讨论】:

标签: html css


【解决方案1】:

class ="placeholder" 上使用data-placeholder 属性:

<div class="placeholder" data-placeholder="New placeholder">
</div>

在 Css 中:

.placeholder {
    position: relative;
}

.placeholder::after {
    position: absolute;
    left: 10px;
    top: 2px;
    content: attr(data-placeholder);
    pointer-events: none;
    opacity: 0.5;
}

这里是JSfiddle

【讨论】:

    猜你喜欢
    • 2013-10-31
    • 1970-01-01
    • 2020-12-09
    • 1970-01-01
    • 2016-05-24
    • 1970-01-01
    • 2023-04-09
    • 2020-10-07
    相关资源
    最近更新 更多