Css pseudo-class, pseudo-element, and css pseudo-class Element

Source: Internet
Author: User

Css pseudo-class, pseudo-element, and css pseudo-class Element

The pseudo class acts on the entire element, for example:

A: link {color: #111 ;}

A: hover {color: #222 ;}

Div: first-child {color: #333 ;}

Although none of these conditions are based on Dom, none of the Results act on a complete element, such as the entire Link, paragraph, and div;

 

A pseudo element acts on a part of an element, for example:

P: first-line {color: #555 ;}

P: first-letter {color: #666 ;}

A pseudo element acts on a part of an element, the first line of a paragraph or the first letter;

 

: Before works the same as: before. The former is css2 and the latter is css3.

 

Role 1:

: Before AND: after can increase the complexity of the pure css design. No extra labels are required. We can use pseudo elements to add extra printable elements or layers. For example, if you want to add a phone icon in front of the phone number font, you can do this:

. PhoneNumber: before {

     content : "☎" ;      font-size : 15px ; } Role 2: Clear floating /* For modern browsers */ .cf:before, .cf:after {      content : "" ;      display :table; }    .cf:after {      clear : both ; }  /* For IE 6/7 (trigger hasLayout) */ .cf {      zoom: 1 ; } Here: before prevents top-margin merge, and after is used to clear floating

 

 

 

 

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.