如何更改CSS输入的占位符?
我有一个看起来像这样的形式的输入:< input type =“ text”占位符=“我的占位符” class =“ form-control datatable-global-filter” value =“> 我希望能够更改CSS中的占位符内容,从
“我的占位符”
到其他东西。我设法通过以下CSS代码来更改颜色和背景以及其他属性,但是我无法更改占位符的内容。我应该放置什么属性,而不是content
?
::placeholder {
font-style: italic;
font-size: 1em;
color: mintcream;
background: thistle;
padding: 5px;
content : "some other placeholder" !important;
}
I have an input in a form that looks like this: <input type="text" placeholder="My placeholder" class="form-control DataTable--global-filter" value="">
I want to be able to change the placeholder content in css, from "My placeholder"
to something else. I managed to change the color and background and the other attributes with the following css snippet, but the content of the placeholder I cannot change. What attribute should I put instead of content
?
::placeholder {
font-style: italic;
font-size: 1em;
color: mintcream;
background: thistle;
padding: 5px;
content : "some other placeholder" !important;
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您不能更改
css
中属性的值,但是如果您的输入位于表单
中,则可以使用棘手的解决方法,您可以使用包装输入
。简而言之:
&lt; span&gt;
元素span ::
pseudoelement 越过输入,并应用您选择的样式:Alterholder
伪class的颜色和背景:占位符
,因此不再可见pointer-events
none
span span ::之前
,因此每次点击此元素都将被忽略并从基础INPUT
元素中截获。输入
表单
is is :有效时,You can't change the value of an attribute in
CSS
but you could use a tricky workaround if your input is inside aform
and you can wrap theinput
.In short:
<span>
elementspan::before
pseudoelement over the input and apply the style you chose for the:placeholder
pseudoclass:placeholder
so it's not visible anymorepointer-events
tonone
forspan::before
so every click to this element will be ignored and intercepted from the underlyinginput
element.input
form
is:valid
then hide the pseudolement