Neither Neither :nth-child
nor :not
work in either IE8 or IE7.
In most cases where you're using these selectors, if you need to support IE7/IE8, you would simply rewrite your HTML so that everything that you need to select with these selectors has a class or an ID that you can select directly. For example, add odd
and even
classes to table rows. That's usually the most sensible solution.
If you absolutely can't rewrite the HTML, then the next best option is to use a polyfill script. The best one to use is Selectivzr. Add this script (along with JQuery if you don't have it already), and it will add support for these selectors to old IE versions. This script does generally work pretty well; however it may have performance implications for your site, and there are quirks, so for example, beware of trying to use the selectors n HTML that is dynamic and gets updated by JavaScript. Be sure to test thoroughly.
Another option is "graceful fallback". As long as your CSS has sensible default values when these selectors don't work, it may not even matter. For example, if you use :nth-child
to highlight alternate rows in a table, does it really matter if IE8 users see all the rows the same colour? Just make sure that the defaults are sensible, and that should be sufficient.
Finally, stop and ask yourself again whether you really need to support IE7 and IE8. These IE versions are very old now and have very low usage rates. Before you do any work, consider the number of users it will affect, and whether it's worth making the effort to do the work required.