Html 过时的元 http-equiv=content-language 的 HTML5 替代品是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8116812/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 11:29:45  来源:igfitidea点击:

What is the HTML5 alternative to the obsolete meta http-equiv=content-language.

htmlvalidationcontent-typemultilingual

提问by Drew

I'm finishing up an HTML5 site that has a mixture of English and Mandarin Chinese.

我正在完成一个混合了英语和普通话的 HTML5 网站。

My validator (HTML5 Validator add-on for FF) is giving me this error:

我的验证器(用于 FF 的 HTML5 验证器附加组件)给了我这个错误:

error: Using the “meta” element to specify the document-wide default
language is obsolete. Consider specifying the language on the root
element instead.

At line 6, column 9: <meta http-equiv="Content-Language" content="en-us" />

the relevant code is:

相关代码是:

<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="content-type" content="text/html; charset=utf-8" />

checking W3.org leads me to this page: telling me that yes, it's obsolete

检查 W3.org 将我带到此页面:告诉我是的,它已过时

I must confess I don't understand how I am supposed to bring this code into compliance?

我必须承认我不明白我应该如何使此代码合规?

I don't know what "specifying the language on the root element"means, or how to do it?

我不知道“在根元素上指定语言”是什么意思,或者怎么做?

Surely <html lang="en">doesn't suffice for UTF-8?

肯定<html lang="en">不够UTF-8

回答by Sal

In HTML5 you can actually define langfor each element. That means if you have a divthat contains Mandarin Chinese in it, just define an attribute lang="zh-CN"for that div, like <div lang="zh-CN">.

在 HTML5 中,您实际上可以lang为每个元素定义。这意味着如果您有一个div包含普通话的lang="zh-CN"div,只需为该 div定义一个属性,例如<div lang="zh-CN">.

回答by Karel

See below for language and charset settings

请参阅下面的语言和字符集设置

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>title</title>
.....