html5 xml css,html - CSS Selector for xml:lang - Stack Overflow

濮阳振海
2023-12-01

The xml:lang attribute will only be effective when the XHTML is interpreted as XML. When it is being parsed as HTML, you need to use the lang attribute.

You can test this by saving your XHTML document locally with a XML file extension and then loading in the browser, and the current CSS selector should work.

If you can control the generation of the XHTML, the easiest thing to do is to use both of the language attributes, to ensure that it is evaluated properly when read as either XML or HTML.

This is described in the W3C international Declaring language in HTML page:

When serving XHTML 1.x or polyglot pages as text/html, use both the lang attribute and the xml:lang attribute together every time you want to set the language. The xml:lang attribute is the standard way to identify language information in XML. Ensure that the values for both attributes are identical.

The xml:lang attribute is not actually useful for handling the file as HTML, but takes over from the lang attribute any time you process or serve the document as XML. The lang attribute is allowed by the syntax of XHTML, and may also be recognized by browsers. When using other XML parsers, however (such as the lang() function in XSLT) you can't rely on the lang attribute being recognized.

 类似资料: