- HTML5 Multimedia Development Cookbook
- Dale Cruse Lee Jordan
- 368字
- 2021-04-02 19:27:38
Specifying the pubdate of an article
"The
pubdate
attribute is a boolean attribute. If specified it indicates that the date and time given by the element is the publication date and time of the nearest ancestor<article>
element, or, if the element has no ancestor<article>
element, of the document as a whole." - WHATWG's HTML5 Draft Standard - http://whatwg.org/html5
Getting ready
The new pubdate
is an attribute for the new <time>
element when it exists within the new <article>
element. It allows us to be even more precise when presenting the date and time of publication.
How to do it...
In this recipe we'll build on the new <time>
element from the last recipe and add the new optional pubdate
attribute to display our publication date.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> <!--[if lt IE 9]><script src=http://html5shiv.googlecode.com/svn/trunk/html5.js> </script>[endif]--> <meta name="viewport" content="width=device-width, initial-scale=1.0"> </head> <body> <article> <header> <h2>Headline</h2> <p>Published on <time datetime="2010-11-29" pubdate> November 29, 2010</time> in the something category.</p> </header> <p>First paragraph</p> <p>Second paragraph</p> <footer></footer> </article> <article> <header> <h2>Headline</h2> <p>Published on <time datetime="2010-11-28" pubdate> November 28, 2010</time> in the something category.</p> </header> <p>First paragraph</p> <p>Second paragraph</p> <footer></footer> </article> </body> </html>
How it works...
Pubdate
is simply a binary variable, or Boolean, attribute to denote when something was published.
There's more...
You can think of pubdate
as adding extra information to an element (<time>)
that is already providing extra information. It is like the cherry on a sundae. And who doesn't like cherries on their sundaes?
Still waiting on browsers
We are getting really forward-thinking by including new elements like <mark>, <time>
, and pubdate
, as none are fully supported by any browser — yet.

Modern browsers like Firefox display the new <time>
element and pubdate
attribute natively without styling.
Extra credit
You can code the new pubdate
Boolean attribute as <time datetime="2010-11-29" pubdate="pubdate">
if you want to conform to XML syntax.
Let's end confusion
Even though HTML5 is still quite new, there's already some confusion about the new pubdate
Boolean attribute. Some think it should generate the date of publication based on your computer clock or a server. That's not its role. Its role is to produce a machine-readable publication date that is useful no matter what text you may put after it.
See also
Tantek Celik has created a very useful site at http://favelets.com that features all sorts of "bookmarklets" or in-browser JavaScript commands. Use these to do things like validate HTML5, CSS, and anchors all in the same window. Very helpful!
- 剪映短視頻制作全流程:剪輯、調(diào)色、字幕、音效
- Creo 4.0中文版從入門到精通
- 從零開始:AutoCAD 2015中文版機械制圖基礎(chǔ)培訓教程
- 中文版After Effects CC實用教程
- Getting Started With Oracle SOA Suite 11g R1 – A Hands/On Tutorial
- UG NX 9.0中文版基礎(chǔ)與實例教程
- iPhone User Interface Cookbook
- 碼上學會:中文版Creo 3.0機械設(shè)計全能一本通(雙色版)
- 神奇的中文版Photoshop CC 2017入門書
- Microsoft Silverlight 4 and SharePoint 2010 Integration
- Altium Designer 21實戰(zhàn)從入門到精通
- Photoshop后期強:多重曝光專業(yè)技法寶典
- Web Host Manager Administration Guide
- Java EE 5 Development with NetBeans 6
- Pluggable Authentication Modules: The Definitive Guide to PAM for Linux SysAdmins and C Developers