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.
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>
In most browsers, the placeholder text is grey. To change this, style the placeholder with the non-standard ::placeholder selector.
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.
Tip: The default color of the placeholder text is light grey in most browsers.
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.
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>
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With