gpt4 book ai didi

html - 有没有办法改变占位符的一个字的颜色

转载 作者:行者123 更新时间:2023-11-27 23:27:25 25 4
gpt4 key购买 nike

假设我有这个文本字段

<input type="text" placeholder="I am placeholder">

我知道用 css 我们可以像这样改变占位符的颜色,但是有没有办法只改变一个单词的颜色。

::-webkit-input-placeholder { /* Chrome/Opera/Safari */
color: pink;
}
::-moz-placeholder { /* Firefox 19+ */
color: pink;
}
:-ms-input-placeholder { /* IE 10+ */
color: pink;
}
:-moz-placeholder { /* Firefox 18- */
color: pink;
}

此代码将更改完整的占位符颜色,但我只想更改单词 placeholder 的颜色而不是完整的 I am placeholder

最佳答案

可以看看mix-blend-mode :

edit: for nowdays,查看并使用下面的更新(第三段)使用background-clip.

label {
display: inline-block;
background: linear-gradient(to right, red 2.2em, blue 2.2em);
border: inset;
/* border here instead input */
font-family: monospace;
/* less surprise about length of text at screen */
}
input {
box-shadow: inset 0 0 0 2em white;
/* covers the background, needed for the blending */
}
input:invalid {
/* color part of text only when placeholder is shown */
mix-blend-mode: screen;
}
/* snippet disclaimer */

.disclaim {
mix-blend-mode: screen;
}
body {
background: white;
}
<label>
<input placeholder="I am placeholder" required />
</label>
<p class="disclaim">not avalaible yet for <span>'your browser',</span> please be patient.</p>

否则您需要使用 HTML 和文本:

label {
display: inline-block;
}
label>span {
position: absolute;
padding-left: 3px;
}
label>span span {
color: blue
}
input {
position: relative;
background: white;
}
input:invalid {
background: none;
}
<label>
<span>I am <span>placeholder</span></span>
<input type="text" required />
</label>


编辑2020

background-clip现在得到很好的支持,可以用来代替 mix-blend-mode

mix-blend-mod 技巧是 Firefoxe 的解决方法。 Firefoxe 理解 color:transparent 但不理解 background-clip-text; 然而...文本不见了。

label {
display: inline-block;
font-family: monospace;
/* less surprise about length of text at screen */
}
input:invalid {
background: linear-gradient(to right, red 2.2em, blue 2.2em);
background-clip:text;
color:transparent;
}
<label>
<input placeholder="I am placeholder" required />
</label>

关于html - 有没有办法改变占位符的一个字的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37699705/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com