What is the use of star-preceded property in CSS ?
It is a simple hack also known as the ‘* property hack’. It is useful when it comes to dealing with the older versions of Internet Explorer (i.e. IE6 and IE7). When we add * before any property name in CSS, it targets IE 7 and below version of IE browsers and reflects when loading the same CSS on the browser while it acts as junk for all other browsers including IE 8 and above.
Note: We can use underscore (_) for IE6 and the star (*) for IE7. Add _ or * in front of a CSS property when required.
color: blue; /* all browsers */ *color: blue; /* IE7 and below */ _color: blue; /* IE6 and below */
Below example illustrate the star-preceded property in CSS:
Example: In this example, we will see how an element preceding with a * behaves differently for different versions in IE. We can see that for element h1 we have added the property color beginning with a *.
Note: It is a kind of bug and it will only works for IE7 and below.
- Output For IE 7 and below: We can see that our h1 property with text GeeksforGeeks is green in color thus, *property name is excepted by this browser version.
- Output For IE 8 and above: We can see that our h1 property with text GeeksforGeeks is black in color showing that *property name is treated as junk in browser IE 8 and above.