HTML5 for Web Designers部分翻譯(含中英文)

第一次翻譯技術類文章,翻譯不好別介意~

 

【原文來自:HTML5 for Web Designers

翻譯:武良呈([email protected])】

 

 

KEEPING IT REAL

保證HTML5規範的合理和實用


 

The creation of HTML5 has been driven by an ongoing internal tension. On the one hand, the specification needs to be powerful enough to support the creation of web applications. On the other hand, HTML5 needs to support existing content, even if most existing content is a complete mess. If the specification strays too far in one direction, it will suffer the same fate as XHTML 2. But if it goes too far in the other direction, the specification will enshrine <font> tags and tables for layout because, after all, that’s what a huge number of web pages are built with. It’s a delicate balancing act that requires a pragmatic, levelheaded approach.

 

HTML5的創建是由其自身壓力驅動的。一方面,規範必須強大到足以支持Web應用程序的創建。另一方面,HTML5的需要支持現有的內容,即使大多數現有的內容槽糕的一塌糊塗。如果規範偏離太遠,它將爲XHTML2遭受同樣的命運。但如果規範在另一個方向走得太同樣也會有失偏頗例如大量網站採用的<font>標籤的存在和不合理地用表格進行佈局。而要保證這兩方面的微妙平衡,需要一個務實,冷靜和理性的方法去實踐。


 

GIVE IT TO ME STRAIGHT,DOCTYPE

Doctype,用最直接的方式展現給我


 

A Document Type Declaration, or doctype for short, has traditionally been used to specify which particular flavor of markup a document is written in.

 

文檔類型聲明,或簡稱DOCTYPE,傳統上一直用於指定聲明某文檔所使用的編寫規則

 

The doctype for HTML 4.01 looks like this:

 

HTML 4.01DOCTYPE的基本書寫方式如下:

<!DOCTYPE HTML PUBLIC »

"-//W3C//DTD HTML 4.01//EN" »

"http://www.w3.org/TR/html4/strict.dtd">

Here’s the doctype for XHTML 1.0:

<!DOCTYPE html PUBLIC »

"-//W3C//DTD XHTML 1.0 Strict //EN" »

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

 

They’re not very human-readable, but, in their own way, they are simply saying “this document is written in HTML 4.01,” or “this document is written in XHTML 1.0.” You might expect the doctype declaring “this document is written in HTML5” would have the number five in it somewhere. It doesn’t. The doctype for HTML5 looks like this: 

 

這種寫法的可讀性不高而這些僅僅是用來聲明"這是按照HTML4.01規範寫的""這是按照XHTML1.0規範寫的"。你可能期望DOCTYPE這樣聲明this document is written in HTML5”。而實際上HTML5的DOCTYPE是這樣的:

 

<!DOCTYPE html>

 

It’s so short that even I can memorize it.

 

這簡單到我都能記住!

 

But surely this is madness! Without a version number in the doctype, how will we specify future versions of HTML?

 

但是,這肯定是太瘋狂了!如果沒有一個版本號的doctype,我們將如何指定的HTML的未來版本? 

 

When I first saw the doctype for HTML5, I thought it was the height of arrogance. I asked myself, “Do they really believe that this will be the final markup specification ever written?”

 

當我第一次看到了HTML5的的doctype這樣聲明會不會過於自信?我問自己:"難道他們真的相信這將是他們寫的最後一個標記規範" 

 

It seemed to be a textbook case of Year Zero thinking.

 

這似乎最新思維方式的經典案例。

 

In fact, though, the doctype for HTML5 is very pragmatic. Because HTML5 needs to support existing content, the doctype could be applied to an existing HTML 4.01 or XHTML 1.0 document. Any future versions of HTML will also need to support the existing content in HTML5, so the very concept of applying version numbers to markup documents is flawed.

 

事實上,HTML5DOCTYPE非常簡約務實。由於HTML5需要支持的現有內容,HTML5文檔類型可用於現有的HTMLXHTML1.0文檔4.01。 HTML的任何未來版本也將支持現有內容,因此應用版本號來標記也就多餘了 

 

The truth is that doctypes aren’t even important. Let’s say you serve up a document with a doctype for HTML 4.01. If that document includes an element from another specification, such as HTML 3.2 or HTML5, a browser will still render that part of the document. Browsers support features, not Doctypes.

 

而且,文檔類型甚至不是重要的。比方說,你的文檔聲明爲HTML4.01。如果該文包括來自其他如HTML3.2HTML5內容規範或者元素瀏覽器將仍然呈現該文檔的那些部分這是瀏覽器支持特點,而與文檔類型基本無關 

 

Document Type Declarations were intended for validators, not browsers. The only time that a browser pays any attention to a doctype is when it is performing “doctype switching”— a clever little hack that switches rendering between quirks mode and standards mode depending on the presence of a decent doctype.

 

文檔類型聲明的目的程序驗證,而不是爲了瀏覽器。瀏覽器唯一一次關注DOCTYPE是當它正在執行DOCTYPE切換(根據doctype切換標準模式之時。

 

The minimum information required to ensure that a browser renders using standards mode is the HTML5 doctype. In fact, that’s the only reason to include the doctype at all. An HTML document written without the HTML5 doctype can still be valid HTML5.

 

HTML5DOCTYPE提供了最少信息量,以保證保證瀏覽器用標準方式渲染文檔。事實上,這DOCTYPE存在的唯一理由一個沒有DOCTYPEHTML文檔依舊可以正常顯示


 

KEEPING IT SIMPLE

保證HTML5的簡單


 

The doctype isn’t the only thing that has been simplified in HTML5.

 

HTML5簡化的不僅僅是doctype聲明標籤。

 

If you want to specify the character encoding of a markup document, the best way is to ensure that your server sends the correct Content-Type header. If you want to be doubly certain, you can also specify the character set using a <meta> tag. Here’s the meta declaration for a document written in HTML 4.01:

 

如果你想指定一個文檔的字符編碼,最好的辦法是要確保你服務器發送正確的Content - Type。如果你加倍仔細,也可以<meta>標記指定使用的字符集。下面是在HTML4.01元的書面文件聲明:

 

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

 

Here’s the much more memorable way of doing the same thing in HTML5:

 

HTML5的方式就簡單好記的多了:

 

<meta charset="UTF-8">

 

As with the doctype, this simplified character encoding contains the minimum number of characters needed to be interpreted by browsers.

 

這是瀏覽器能識別接受的最簡約的字符集聲明瞭

 

The <script> tag is another place that can afford to shed some fat. It’s common practice to add a type attribute with a value of “text/javascript” to script elements:

 

<script>標籤是另一個例子。這是常見的做法是添加javascript實例 

 

<script type="text/javascript" src="file.js"></script>

 

Browsers don’t need that attribute. They will assume that the script is written in JavaScript, the most popular scripting language on the web (let’s be honest: the only scripting language on the web):

 

瀏覽器不需要這些屬性。HTML5假定文檔腳本語言就是JavaScript網上最流行的腳本語言,說實話,這確實是唯一的Web腳本語言

 

<script src="file.js"></script>

 

Likewise, you don’t need to specify a type value of “text/css” every time you link 

to a CSS file:

 

而在文檔中添加CSS文件的標籤同樣也瘦了一大圈,下面以前版本的標籤:

 

<link rel="stylesheet" type="text/css" href="file.css">

 

You can simply write:

 

而你可以這樣簡寫:

 

<link rel="stylesheet" href="file.css">

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章