javascript - How to apply name with black colour & Star with red colour to into Placeholder Star as a Required filed? -

Into input placeholder, I'm trying to set placeholder-name with black color & Star with red co

Into input placeholder, I'm trying to set placeholder-name with black color & Star with red color as a Required filed but didn't apply an only specific red color to Star, so is there any another way to set color Please suggest me best way?

Already tried to set using but didn't get proper resolution,

::-WebKit-input-placeholder:after { content: "*"; color: red; }

Demo Mentioned below:

Into input placeholder, I'm trying to set placeholder-name with black color & Star with red color as a Required filed but didn't apply an only specific red color to Star, so is there any another way to set color Please suggest me best way?

Already tried to set using but didn't get proper resolution,

::-WebKit-input-placeholder:after { content: "*"; color: red; }

Demo Mentioned below:

Share Improve this question asked Mar 14, 2019 at 9:58 Siddharth panchalSiddharth panchal 1012 silver badges13 bronze badges 3
  • 2 Have you tried this answer? : stackoverflow./questions/22415875/… Let me know ! – Marin Mouscadet Commented Mar 14, 2019 at 10:05
  • 3 Possible duplicate of 2 colors in one placeholder of input field – AG_ Commented Mar 14, 2019 at 10:08
  • 1 Possible duplicate of Add span inside form's placeholder – vrintle Commented Mar 14, 2019 at 10:14
Add a ment  | 

3 Answers 3

Reset to default 4

It will work for you. I have just codded for single field.

.form-group{position:relative;}
.form-group input{position:relative;z-index:9;background:transparent;border:1px solid #aaa;padding: 5px}
.form-group label{position:absolute;left:5px;top:5px;z-index:1;color:#ccc;}
.form-group label::after{content:"*";color:red;}
input[required]:valid + label{display: none;}
<div class="form-group">
  <input type="text"  name="name" required="required" />
  <label>Enter first name</label>
</div>

There is no perfect solution.

The first option is to use background images, but the star position must be set manually for every field:

input::placeholder {
  background-image: url('images/some-red-star.png') no-repeat;
  background-position-x: 50px;
}

If you can't afford to place manually every star you use a fake html placeholder by placing a div bellow every and making it behave as a placeholder:

<input required="required">
<div class="placeholder">name<span>*</span>

.placeholder { 
  position: ... 
  pointer-events: none;
  user-select: none;
}
.placeholder > span { color: red; }
input:valid ~ .placeholder {
  display: none;
}

Try This I think it's useful for you

input {
 width: 200px;
 padding: 8px;
}

input[required] + label {
  position: relative;
  color: #000;
  font-size: 16px;
  left: -210px;
}

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

.btn {
  width: auto;
  margin: 10px 0;
}
<form>
  <input type="text" id="box1" required="required" />
    <label for="name">Enter First Name</label><br/><br/>
  <input type="text" id="box1" required="required" />
    <label for="name">Enter Last Name</label><br/>
  <input class="btn" type="submit" />
</form>

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745667235a4639192.html

相关推荐

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信