I need to set * in red color in a textfield's placeholder to indicate that the field is mandatory to be filled. I'm using ExtJS with CSS.
Asked
Active
Viewed 854 times
-1
2 Answers
1
Well not possible with css
or placeholder
attribute...You will need a hack by creating a element for the placeholder text like span
and style it look like placeholder...
Also you will need some jQuery to check that the input is empty or not to just show or hide the placeholder text
$(".input-control input").on("blur input", function() {
if ($(this).val() != "") {
$(this).next(".placeholder").hide();
} else {
$(this).next(".placeholder").show();
}
})
.input-control {
position: relative;
font: 13px Verdana;
}
.input-control input {
width: 200px;
height: 30px;
padding: 0 10px;
}
.input-control .placeholder {
position: absolute;
left: 12px;
line-height: 30px;
color: #bbb;
top: 0;
pointer-events: none;
}
.input-control .placeholder sup {
color: red;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class="input-control">
<input type="text">
<span class="placeholder">User Id<sup>*</sup></span>
</div>

Bhuwan
- 16,525
- 5
- 34
- 57
-
-
@DivakarArasu Actually I don't have any idea about extjs...I am just checking it...I will get back to you if I found anything... – Bhuwan Mar 15 '18 at 10:17
-
@DivakarArasu you can read this https://stackoverflow.com/questions/14776874/use-extjs-and-jquery-together-in-one-application – Bhuwan Mar 15 '18 at 10:30
0
Unfortunately, it's not possible to style different parts of placeholder text by default...
You can of course apply one style to the placeholder text though using the ::placeholder
attribute:
However, there is a way to get support for most browsers that does what you require. There isn't a universal way of doing what you want easily so this might be a long shot...as long as you don't need support for older IE browsers, you should be okay with the following approach:
input::-webkit-input-placeholder:after {
content: " *";
color: red;
}
input:-moz-placeholder:after {
content: " *";
color: red;
}
input:-ms-input-placeholder:after {
content: " *";
color: red;
}

A Friend
- 1,420
- 17
- 22
*
' – Divakar Arasu Mar 15 '18 at 07:03