Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Purpose of asterisk before a CSS property

Tags:

css

The following is taken from the Yahoo CSS reset. Can someone please explain the purpose of the asterisks?

body {   font:13px/1.231 arial,helvetica,clean,sans-serif;   *font-size:small;   *font:x-small; } 
like image 746
Jeremy Avatar asked Nov 06 '09 21:11

Jeremy


People also ask

Why do we use * in CSS?

The asterisk (*) is known as the CSS universal selectors. It can be used to select any and all types of elements in an HTML page. The asterisk can also be followed by a selector while using to select a child object. This selector is useful when we want to select all the elements on the page.

What does the asterisk mean in CSS?

The Universal Selector is the * in CSS. Literally the asterisk character. It is essentially a type selector that matches any type. Type meaning an HTML tag like <div> , <body> , <button> , or literally any of the others. A common use is in the universal reset, like this: * { margin: 0; padding: 0; }


1 Answers

It is a browser specific CSS hack for versions 7 or below of Internet Explorer.

*property: value

Although Internet Explorer 7 corrected its behavior when a property name is prefixed with an underscore or a hyphen, other non-alphanumeric character prefixes are treated as they were in IE6. Therefore, if you add a non-alphanumeric character such as an asterisk (*) immediately before a property name, the property will be applied in IE and not in other browsers. Unlike with the hyphen and underscore method, the CSS specification makes no reservations for the asterisk as a prefix, so use of this hack could result in unexpected behavior as the CSS specifications evolve.

*property: value applies the property value in IE 7 and below. It may or may not work in future versions. Warning: this uses invalid CSS.

From: http://www.javascriptkit.com/dhtmltutors/csshacks3.shtml

like image 148
Waleed Amjad Avatar answered Sep 19 '22 22:09

Waleed Amjad