Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change input placeholder * color only

I have multiple input fields some fields are required and required field mention with * so I need to change input placeholder * color only, not change whole placeholder color check below image what I exactly need.

enter image description here
I have tried below code to achieve this but it can change whole color of placeholder

div {
  margin:10px 0px;
}
input {
  width: 200px;
  border: none;
  border-bottom: solid 1px #8d97a0;
  padding: 5px;
  border-radius: 0;
  background: #fff;
  box-shadow: none;
}
::-webkit-input-placeholder {
  color:red;
}
<div>
  <input type="name" name="name" id="name" placeholder="Name *">
</div>
<div>
  <input type="Email" name="email" id="email" placeholder="Email">
</div>
<div>
  <input type="phone" name="phone" id="phone" placeholder="Phone">
</div>
<div>
  <input type="password" name="password" id="password" placeholder="Password *">
</div>
like image 633
Ezzuddin Avatar asked Oct 31 '17 05:10

Ezzuddin


People also ask

How can I change placeholder color of specific input?

In most browsers, the placeholder text is grey. To change this, style the placeholder with the non-standard ::placeholder selector.

How do you change the color of the placeholder text?

The default color of a placeholder text is light grey in most browsers. If you want to change it, you need to use the ::placeholder pseudo-element. Note that Firefox adds lower opacity to the placeholder, so use opacity: 1; to fix it.

What is input placeholder color?

Tip: The default color of the placeholder text is light grey in most browsers.

How do I change placeholder text in CSS?

Change Input Placeholder Text with CSS You can use the ::placeholder pseudo-element to change the styles of the placeholder text, which includes the ability to change the background. The code in this example uses a Sass function to generate code for support in older browsers as well.


2 Answers

Try this:

label {
  display: inline-block;
  width:100%;
  background: linear-gradient(to right, #999 6em, red 5em);
  border: 2px solid #ccc;
  font-family: monospace;/* less surprise about length of text at screen */
}
input {
  font-weight: bold;
  width: 100%;
  height:20px;
  padding:10px;
  border: none;
  display: block;
outline:none;

}
input:invalid {/* color part of text only when placeholder is shown */
  mix-blend-mode: screen;
}
<label>
  <input placeholder="Password *" required />
</label>
like image 104
Hrishabh Singh Avatar answered Sep 28 '22 11:09

Hrishabh Singh


Just placeholder wont give different styles.If you want different style you need to separate like this.

input {
    width: auto;
}

input + label {
    color: #999;
    font-family: Arial;
    font-size: .8em;
    position: relative;
    left: -166px; 
}

input[required] + label:after {
    content:'*';
    color: red;
}


input[required]:invalid + label {
    display: inline-block;
}

input[required]:valid + label{
    display: none;
}
<div>
  <input type="text" id="name" name="name" required="required" />
  <label for="name">Password</label>
</div>
like image 38
Bharath Kumar Avatar answered Sep 28 '22 13:09

Bharath Kumar