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!