CSS example of adding asterisks to form-required options

Source: Internet
Author: User

When making a Web page form, if an option is required, an asterisk is usually added to the option, such as WordPress's comment form:

<p class= "Form-group" >
<label for= "Author" > Name </label> <span class= "required" >*</span>
<input type= "text" id= "author" name= "author" required= "Required" "size=" class= "Form-text" >
</p>

Then add a little CSS style to the asterisk:


. Form-group span.required {
Color: #999;
font-size:150%;
}
CSS add asterisks to form required options

But sometimes we may not be able to modify the HTML structure, or do not want to add extraneous meaningless tags, then we can use the CSS after pseudo class to create an asterisk.

Or the top of the form, delete <span class= "required" >*</span> this code, and then add CSS:


. Form-group Label:after {
Content: ' * ';
Color: #999;
font-size:150%;
}

This allows you to create an asterisk that represents a required selection by using CSS.

In fact, CSS before and after pseudo class is very easy to use, most people just take it to clear floating, in fact, the brain open a bit, take advantage of these two pseudo class can make very magical things.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.