公共网站应选择哪种 HTML 版本

发布于 2024-10-13 18:26:19 字数 184 浏览 6 评论 0原文

我目前正在一个网站上工作。在研究了 HTML5 及其功能之后,我想继续使用它。我想使用离线存储、数据属性、简单聊天支持等功能,但由于 HTML5 还没有得到很好的支持,我有点困惑。到目前为止我一直使用 XHTML 1.0 过渡;我应该继续使用它还是应该使用 HTML5?

我看到像 google 这样的网络巨头已经完全转向 HTML5 了。

I am currently working on a website. After studying HTML5 and its features I want to go ahead with it. I want to use features like offline storage, data- attribs, simple chat support etc. but because HTML5 is not well-supported yet, I am a bit confused. I have always used XHTML 1.0 transitional until now; should I continue using it or should I use HTML5?

I have seen the web giants like google have completely shifted to HTML5.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

彼岸花似海 2024-10-20 18:26:19

HTML5 功能

如果您指的是 HTML5 功能,那么您必须了解 HTML5 到底是什么。我认为它具有以前规格的巅峰以及更新和更丰富的功能。它旨在支持现有内容(向后兼容)并支持 Web 应用程序的创建。真正令人惊叹的是它不仅仅止于此。它首次规定了浏览器应如何处理错误处理。

现在,您需要知道并非所有功能都在浏览器中实现。您可以进行 HTML5 浏览器测试来了解哪些有效,哪些无效。这并不意味着它们不起作用!大多数浏览器实际上允许您使用您想要发明的任何元素并为其设计样式。新的 HTML5 标签在不支持它们的浏览器中没有默认样式。

以下 CSS 代码对于大多数浏览器来说就足够了:

section, article, header, footer, nav, aside, hgroup {
  display: block;
}

与往常一样,Internet Explorer (IE) 有特殊需求。只是,有一位名为 Remy Sharp 的 JavaScript 魔术师创建了一个 JavaScript 文件,该文件为 IE 创建每个元素。因此,您可以在页面中添加以下内容:

<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"
  </script>
<![endif]-->

顺便说一句,您必须使用 JavaScript 才能测试新 HTML5 元素的存在,并为那些浏览器无法跟上某些 HTML5 元素速度的用户提供替代选择和属性。这就是为什么有一个通用的 JavaSCript 小函数可以用来做到这一点:

function elementSupportsAttribute(element, attribute) {
  var test = document.createElement(element);
  if(attribute in test)
    return true;
  else
    return false;
}

最后一点,我从书中获得了大部分信息 HTML5 网页设计师。向杰里米·基思致敬!


HTML5 Doctype

如果您指的是新的 doctype ,这就是我要说的...

在 HTML5 中使用以前的 HTML/XHTML 版本的功能并不违法。请注意,新的文档类型没有任何与之关联的编号。这是因为它旨在建立在现有规范的基础上并对未来版本有效。因此,我建议你使用新的文档类型。

您可以查看 W3C 网站上的规范。简而言之,规范说的是......

8.1.1 文档类型

DOCTYPE 是必需的前导码。

旧版需要 DOCTYPE
原因。当省略时,浏览器倾向于
使用不同的渲染模式
与某些不兼容
规格。包括 DOCTYPE
在文档中确保浏览器
尽最大努力
遵循相关规范。

[...]

用于 HTML 目的
无法输出 HTML 的生成器
带有短 DOCTYPE 的标记
”,DOCTYPE 遗产
字符串可以插入到
DOCTYPE(在定义的位置
上)。

HTML5 Features

If you mean the HTML5 features, you must understand what HTML5 really is. I would define it has the culmination of the previous specs as well as newer and richer features. It is made to support existing content (backward compatible) and to support the creation of web applications. What is really awesome is the fact that it does not only stop there. It states for the first time how browsers should deal with error handling.

Now, you need to know that not all features are implemented in browsers. You can take an HTML5 browser test to know what works and what doesn't. That does not mean that they will not work! Most browsers actually allow you to use and style any element you care to invent. The new HTML5 tags have no default style in browsers that do not support them.

The following CSS code would be enough for most browsers:

section, article, header, footer, nav, aside, hgroup {
  display: block;
}

As always, Internet Explorer (IE) has special needs. Only, there is a JavasScript magician who goes by the name of Remy Sharp that has created a JavaScript file that creates each element for IE. So you could add this in your page:

<!--[if IE]>
  <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"
  </script>
<![endif]-->

By the way, you will have to use JavaScript to be able to test the existence of new HTML5 elements and give an alternate choice to those who have browsers that are not up to speed with certain HTML5 element and attributes. This is why there is this little generic JavaSCript function that you can use to do just that:

function elementSupportsAttribute(element, attribute) {
  var test = document.createElement(element);
  if(attribute in test)
    return true;
  else
    return false;
}

One last note, I got most of this information from the book HTML5 For Web Designers. Kudos to Jeremy Keith!


HTML5 Doctype

If you mean the new doctype one <!DOCTYPE HTML>, here is what I have to say...

It isn't illegal to use features from previous HTML/XHTML version in HTML5. Note that the new doctype does not have any number associated with it. That is because it is meant to build upon existing specs and to be valid for future versions. Therefore, I say that you go with the new doctype.

You can have a look at the spec on the W3C site. In short the spec says this...

8.1.1 The DOCTYPE

A DOCTYPE is a required preamble.

DOCTYPEs are required for legacy
reasons. When omitted, browsers tend
to use a different rendering mode that
is incompatible with some
specifications. Including the DOCTYPE
in a document ensures that the browser
makes a best-effort attempt at
following the relevant specifications.

[...]

For the purposes of HTML
generators that cannot output HTML
markup with the short DOCTYPE
"<!DOCTYPE html>", a DOCTYPE legacy
string may be inserted into the
DOCTYPE (in the position defined
above).

紫﹏色ふ单纯 2024-10-20 18:26:19

HTML5 是一组基本不相关的功能。

您可以使用任何您想要的功能;您只需要了解哪些浏览器支持哪些功能

HTML5 is a set of mostly-unrelated features.

You can use whichever features you want; you just need to be aware of which browsers support which features.

山色无中 2024-10-20 18:26:19

与其他语言不同,您不必在 HTML 5 和 XHTML 之间进行选择。我认为你的问题来自于看到 HTML 源代码顶部的 DOCTYPE 字符串。您应该包含 DOCTYPE,但这对于浏览器支持来说并不重要。

正确的问题是浏览器是否支持您想要使用的功能。每个浏览器都支持 HTML 5 的部分功能,因为 HTML 5 的大部分功能与 HTML 4 和 XHTML 相同。考虑您的目标受众以及他们可能使用的浏览器,然后查看这些浏览器对您想要使用的功能的支持程度。

简而言之,您不必决定是否要使用 HTML 5,您需要逐个功能地单独决定该功能是否得到足够好的支持(无论该功能是否是特定于 HTML 5 的)是否有功能)。

这是浏览器支持 HTML 5 的一些新功能的好资源: http://www.findmebyip.com/litmus

Unlike other languages, you don't have to choose between HTML 5 and XHTML. I think your question is coming form seeing the DOCTYPE string at the top of HTML source. You should include a DOCTYPE, but it doesn't matter much to browser support.

The right question to ask is if there is browser support for the features you want to use. Every browser supports some features of HTML 5, since most of HTML 5 is the same as HTML 4 and XHTML. Consider your target audience and what browsers they probably use and then look up how well those browsers support the features you want to use.

In short, you don't have to decide if you want to use HTML 5, you need to decide individually on a feature-by-feature basis if that feature is well enough supported (no matter if that feature is an HTML 5-specific feature or not).

This is a good resource for browser support of some of HTML 5's new features: http://www.findmebyip.com/litmus

别把无礼当个性 2024-10-20 18:26:19

完全取决于网站的用户以及他们的浏览器支持哪些功能。正如 SLAks 所说,HTML5 并不是一个全有或全无的主张。

Mark Pilgrim 有两章很好的章节介绍了通过 JavaScript 检测对 HTML 功能的支持(这是唯一可靠的方法):

您在这里使用开发人员一直用于前端 Web 代码的相同方法 - 使用新功能,以便尚不具备该功能的用户仍然可以使用该网站,即使体验对他们来说并不那么顺利。

Depends entirely on the users of the website, and which features their browsers support. As SLaks said, HTML5 isn’t an all-or-nothing proposition.

Mark Pilgrim has two good chapters on detecting support for HTML features via JavaScript (which is the only reliable way to do it):

You use the same approach here that developers have always used for front-end web code — use new features in such a way that users who don’t have that feature yet can still use the site, even if the experience isn’t as slick for them.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文