Detailed introduction to the class name problem in css

王林
Release: 2020-03-27 10:11:48
forward
2376 people have browsed it

Detailed introduction to the class name problem in css

The following CSS class names starting with numbers will not take effect:

.1st{
    color: red;
}
Copy after login

A legal CSS class name must start with one of the following:

1. Underscore_

2. Dash-

3. Letter a - z

followed by other _, - numbers or letters.

(Recommended tutorial: CSS Getting Started Tutorial)

Using regular expressions, a legal CSS class name:

-?[_a-zA-Z]+[_a-zA-Z0-9-]*
Copy after login

According to CSS According to the description in the standard, if the class name starts with a dash -, the second character must be an underscore _ or a letter, but actual testing found that in addition to the two mentioned, it is also valid to be followed by another dash.

The following is the test code and results:

<p class="1st">should apply red color</p>
<p class="-1foo">should apply red color</p>
<p class="-_foo">should apply red color</p>
<p class="--foo">should apply red color</p>
<p class="-foo">should apply red color</p>
<p class="foo">should apply red color</p>
.1st {
  color: red;
}
.-1foo {
  color: red;
}
.-_foo {
  color: red;
}

.--foo {
  color: red;
}

.-foo {
  color: red;
}
.foo {
  color: red;
}
Copy after login

The results are as shown:

Detailed introduction to the class name problem in css

## Recommended related video tutorials:

css video tutorial

The above is the detailed content of Detailed introduction to the class name problem in css. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:jb51.net
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template