Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
526 views
in Technique[技术] by (71.8m points)

html - Is there any way to change one word color of placeholder

Suppose i have this text field

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

I know with css we can change placeholder color like this but is there any way to change color of one word only.

::-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;
}

This code will change complete placeholder color but i want to change color of word placeholder only instead on complete I am placeholder

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can take a look at mix-blend-mode :

edit: for nowdays, see and use update below (3rd snippet) with 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>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...