The CSS descendant selector is compatible with IE8 and IE8

Source: Internet
Author: User

CSS descendant selectors are very useful and make our work more convenient. But there's a problem, IE8 and IE8. The following are not compatible with many descendant selectors.

These six descendant selectors are relatively long-used:

You will find that IE9 is compatible with these descendant selectors. IE8, IE7 except for: First-child is compatible, the other five are incompatible.

Compatible:

<body>     <div>           <p>aaaa</p>           <p>aaaa</p>           <p>aaaa</p >           <p>aaaa</p>     </div>        </body>

First, let the 2nd P element become a "blue" font.

This is generally the case with Div p:nth-child (2) {color:blue;}

or div p:nth-of-type (2) {color:blue;}

Or just add class to the 2nd P element.

To be compatible on IE7,IE8:

The first method: Div>p:first-child+p {color:blue;}

The second approach is to use jquery:

if (navigator.appname = = = ' Microsoft Internet Explorer ') {//Determine if it is IE browser   if (Navigator.userAgent.match (/trident/i) & amp;& Navigator.userAgent.match (/msie 8.0/i)) {           $ (' P:nth-child (2) '). CSS (' Color ', ' blue ');
$ (' P:nth-of-type (2) '). CSS (' Color ', ' Blue ');} }

First, let the 2nd, 4th p elements into a "blue" font.

This is generally the case with Div p:nth-child (2n) {color:blue;}

or div p:nth-of-type (2n) {color:blue;}

To be compatible on IE7,IE8: DF SASDA

if (navigator.appname = = = ' Microsoft Internet Explorer ') {//Determine if it is IE browser   if (Navigator.userAgent.match (/trident/i) & amp;& Navigator.userAgent.match (/msie 8.0/i)) {           $ (' P:nth-child (2n) '). CSS (' Color ', ' blue ');        $ (' P:nth-of-type (2n) '). CSS (' Color ', ' Blue ');}   }

: Nth-child (Odd),: Nth-child (odd) odd even number, can also be handled this way.

The CSS descendant selector is compatible with IE8 and IE8

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.