Home >Web Front-end >CSS Tutorial >Why Are Asterisks Used as Prefixes in Some CSS Properties?

Why Are Asterisks Used as Prefixes in Some CSS Properties?

Linda Hamilton
Linda HamiltonOriginal
2024-12-18 05:23:09696browse

Why Are Asterisks Used as Prefixes in Some CSS Properties?

Using Asterisk Prefix in CSS: A Browser-Specific Hack

The Yahoo CSS reset includes the following lines:

body {
  font:13px/1.231 arial,helvetica,clean,sans-serif;
  *font-size:small;
  *font:x-small;
}

The presence of asterisks before certain CSS properties raises the question of their purpose.

Answer:

The asterisks serve as a browser-specific CSS hack, primarily targeting Internet Explorer versions 7 and below. This hack takes the following form:

*property: value

While Internet Explorer 7 has addressed issues related to underscores and hyphens preceding property names, it continues to treat non-alphanumeric prefixes differently. Consequently, by adding an asterisk immediately before a property name, developers can ensure that the property is applied in IE, but not in other browsers.

It's important to note that this hack relies on invalid CSS. Moreover, future updates to the CSS specifications may render it ineffective. Therefore, it should be used with caution and only as a temporary solution.

The above is the detailed content of Why Are Asterisks Used as Prefixes in Some CSS Properties?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn