Detailed explanation of the problem of CSS class names

Detailed explanation of the problem of CSS class names

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

.1st{
    color: red;
}

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

• Underscore_
•Hash-
• Letters a - z

Then followed by another _ , - , number or letter.

In regular expression, a legal CSS class name is:

-?[_a-zA-Z]+[_a-zA-Z0-9-]*

In addition, according to the description in the CSS standard, if the class name starts with a hyphen - , the second character must be an underscore _ or a letter, but actual testing has found that in addition to the two mentioned, following another hyphen is also effective.

The following are the test codes 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;
} 

Actual effects of different class names

Summarize

The above is a detailed explanation of the CSS class name problem introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to you in time. I would also like to thank everyone for their support of the 123WORDPRESS.COM website!

<<:  Web design must also first have a comprehensive image positioning of the website

>>:  Shtml Concise Tutorial

Recommend

MySQL 5.7.18 release installation guide (including bin file version)

The installation process is basically the same as...

Common date comparison and calculation functions in MySQL

Implementation of time comparison in MySql unix_t...

Detailed explanation of CSS counter related attributes learning

The CSS counter attribute is supported by almost ...

js to realize payment countdown and return to the home page

Payment countdown to return to the home page case...

MySQL 8.0.12 installation and configuration method graphic tutorial

Record the installation and configuration method ...

MySQL 5.7.20 zip installation tutorial

MySQL 5.7.20 zip installation, the specific conte...

How to use cookies to remember passwords for 7 days on the vue login page

Problem Description In the login page of the proj...

Detailed introduction to the MySQL installation tutorial under Windows

Table of contents 1. Some concepts you need to un...

An article teaches you how to use js to achieve the barrage effect

Table of contents Create a new html file: Create ...

How to run sudo command without entering password in Linux

The sudo command allows a trusted user to run a p...

How to use the dig/nslookup command to view DNS resolution steps

dig - DNS lookup utility When a domain name acces...

JavaScript implements H5 gold coin function (example code)

Today I made a Spring Festival gold coin red enve...

Personalized and creative website design examples (30)

Therefore, we made a selection of 30 combinations ...