是否可以在 input
字段的占位符属性中使用 HTML 效果?例如,下面可以是输入字段占位符的输出吗?
normal bold
可以使用带有 ::placeholder
的 CSS 自定义占位符,但它适用于其中的所有文本。如何像 HTML 一样调整它?
最佳答案
我猜你可以创建一个类似“占位符”的效果来做你想做的事。像这样:
.inputBox {
position: relative;
display: inline-block;
}
.placeholder {
position: absolute;
top: 50%;
transform: translateY(-50%);
left: 2px;
width: 100%;
height: 100%;
pointer-events: none;
opacity: 0.85;
}
.inputBox input:focus+.placeholder {
display: none;
}
.inputBox input:valid+.placeholder {
display: none;
}
<div class="inputBox">
<input type="text" required />
<div class="placeholder"><span style="font-weight: bold">Bold</span> <span>Text</span><!-- your html here --></div>
</div>
关于javascript - 使用 CSS 样式化输入字段的占位符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50707056/