change only the asterisk in placeholder to red

时光总嘲笑我的痴心妄想 提交于 2021-02-10 16:00:34

问题


I am having trouble with a placeholder. I would like to change the color of the asterisk inside of the placeholder to red and leave the rest the dim black.

I am using bootstrap .form-control for markup.

I would like to know if there is a plugin/easy method of doing this. JS or CSS.


回答1:


I don't know of any easy way to have 2 colors in a place holder.

You can try adding an asterisk after your placeholder using -webkit-input-placeholder::after, and change its color, but this solution does not work in all browsers: See here

You can try something like this and add your placeholder as a label...

input[required] + label {
    position: relative;
    left: -170px; /* move the label left and place it inside the input */
    color: #757575; /* placeholder color here */
}

input[required] + label:after {
    content:'*';
    color: red;
}
<input type="text" id="myInput" name="myInput" required="required" />
<label for="myInput">IME IN PRIIMEK</label>


来源:https://stackoverflow.com/questions/50429681/change-only-the-asterisk-in-placeholder-to-red

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!