Home > Web Front-end > CSS Tutorial > Can CSS Classes Starting with Numbers Be Validated?

Can CSS Classes Starting with Numbers Be Validated?

Mary-Kate Olsen
Release: 2024-11-01 06:55:02
Original
409 people have browsed it

Can CSS Classes Starting with Numbers Be Validated?

Can CSS Classes Starting with Numbers Be Validated?

Many CSS classes begin with numbers, but according to CSS syntax, selectors like .000000-8 are invalid due to the first character being a digit. However, there is a workaround to validate these classes.

Despite the HTML5 restriction against whitespace characters in class names, there are no limitations on using digits as the starting character. Therefore, class names like 000000-8 are valid in HTML.

To use these class names in CSS, escape the digit using CSS escaping rules. Escape characters use hexadecimal digits, resulting in selectors like .30 000000-8 or .00003000000-8. Both selectors will match elements with the class 000000-8.

While class names starting with numbers should usually be avoided, this workaround provides a solution if necessary, such as when working with unmodifiable HTML documents that contain such class names.

The above is the detailed content of Can CSS Classes Starting with Numbers Be Validated?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
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
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template