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

Detailed explanation of the Docker deployment tutorial for Jenkins beginners

This article deploys Jenkins+Maven+SVN+Tomcat thr...

Significantly optimize the size of PNG images with CSS mask (recommended)

This article is welcome to be shared and aggregat...

About Tomcat combined with Atomikos to implement JTA

Recently, the project switched the environment an...

CSS achieves highly adaptive full screen

When writing my own demo, I want to use display:f...

Div exceeds hidden text and hides the CSS code beyond the div part

Before hiding: After hiding: CSS: Copy code The co...

Learn MySQL database in one hour (Zhang Guo)

Table of contents 1. Database Overview 1.1 Develo...

How to customize an EventEmitter in node.js

Table of contents Preface 1. What is 2. How to us...

Tic-Tac-toe game implemented in pure CSS3

Operation effect: html <div class="tic-ta...

Summary of the use of special operators in MySql

Preface There are 4 types of operators in MySQL, ...

Alibaba Cloud Server Ubuntu Configuration Tutorial

Since Alibaba Cloud's import of custom Ubuntu...

Will the index be used in the MySQL query condition?

When an employer asks you whether an index will b...

JavaScript implements countdown on front-end web page

Use native JavaScript to simply implement the cou...

How to use linux commands to convert and splice audio formats

Install FFmpeg flac eric@ray:~$ sudo apt install ...