简体   繁体   中英

How to add red required text to an input when the field has not been filled out

I would like to add a red required text on the right side of a text input. I would want it to look similar to this. An email field with the required tag.

I apologize for not have code to add, the only things ive tried have been messing with placeholders as i have no idea which direction to go for this. Any help is much appreciated.

You may want to consider something like this.

 input { padding: 1em; width: 250px; } /* Position label on top of input field */ label { margin-left: -80px; position: relative; z-index: 2; } /* Show red label when input invalid */ input:required:invalid+label { color: red; } /* Don't display label when input is valid */ input:required:valid+label { display: none; }
 <input type="email" id="email_input" placeholder="Email" required> <label for="email_input">Required</label>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM