tossug html5 讀書會 新標籤與表單
DESCRIPTION
語義網、新標籤、新表單TRANSCRIPT
HTML5 The Missing Partothree
Outline
• Semantic Web
• HTML5 標籤與屬性
• Web Forms 2.0
Semantic Web
• Tim Bernes Lee 目前主力推動目標
What is Semantic Web
• 網路上的資料都有電腦可以理解的意義標記
So
• 想像有一天全部的資料可以連結起來
How ?
• XML for data
• (X)HTML for web content
(X)HTML Standards
• HTML 4.01: Still using today
• XHTML 1: Bridge between HTML and XML
• XHTML 1.1: Preparing for Semantic Web
• XHTML 2.0 (廢棄)
XHTML 2.0
• 烏托邦的標準• 太嚴格,不向下相容• ex: no <h1> ~ <h6>, <br>
一次到位是有難度的
How ?
• 正確的使用標籤• <table> for 表格資料 not 排版
• <p> for 段落
• <h1> ~ <h6> for 標題 not 大字體
• <blockquote> for 引言 not 縮排
• 不使用 <b>, <i>, <u>, <big>, <small>
http://www.certifiedchinesetranslation.com/openaccess/rdfa-primer.html
2nd Step
• 使用 RDFa, Microformats ... etc
HTML
<div> 我是 Bob Smith, 不過朋友都叫我 Smithy。 以下是我的首頁網址: <a href="http://www.example.com">www.example.com</a>. 我住在 Albuquerque (NM),目前服務於ACME Corp., 擔任工程師一職。</div>
http://www.google.com/support/webmasters/bin/topic.py?topic=21997
vCardBEGIN:VCARDVERSION:3.0N:Bob SmithFN:Bob SmithNICKNAME:SmithyURL: http://www.example.comTITLE:工程師ORG:ACME CorpADR;TYPE=work:;;;Albuquerque;NM;;END:VCARD
http://www.google.com/support/webmasters/bin/topic.py?topic=21997
RDFa
<div xmlns:v="http://rdf.data-vocabulary.org/#" typeof="v:Person"> 我是 <span property="v:name">Bob Smith</span>, 不過朋友都叫我 <span property="v:nickname">Smithy</span>。 以下是我的首頁網址: <a href="http://www.example.com" rel="v:url">www.example.com</a>. 我住在 Albuquerque (NM),目前服務於 <span property="v:affiliation">ACME Corp</span>., 擔任<span property="v:title">工程師</span>一職。</div>
http://www.google.com/support/webmasters/bin/topic.py?topic=21997
Microformats
<div class="vcard"> 我是 <span class="fn">Bob Smith</span>, 不過朋友都叫我 <span class="nickname">Smithy</span>。 以下是我的首頁網址: <a href="http://www.example.com" class="url">www.example.com</a>. 我住在 Albuquerque (NM),目前服務於 <span class="org">ACME Corp</span>., 擔任<span class="title">工程師</span>一職。</div>
http://www.google.com/support/webmasters/bin/topic.py?topic=21997
MicroformatshCalendar
hCard
rel-license
rel-nofollow
rel-tag
XFN
XOXO
...
Benefits
• 親和力 (Accessibility)
• SEO
• 第三方應用• 爽
HTML Standards
• HTML 4.01: Still using today
• XHTML 1: Bridge between HTML and XML
• XHTML 1.1: Preparing for Semantic Web
• XHTML 2.0 (廢棄)
• (X)HTML5 by WHATWG
HTML5 New Elements
New Structure Elements
<header>
<footer>
<nav>
<aside>
<article>
<hgroup>
<section>
A Web Page<div id=”header”></div>
<div id=”footer”></div>
<ul id=”navigator”></ul>
<div id=”content”></div> <div id=”sidebar”></div>
A Web Page in HTML5<header></header>
<footer></footer>
<nav></nav>
<div id=”content”></div><aside></aside>
Structure Elements
• <header> 頁首資訊:標題、作者
• <footer> 頁尾資訊:著作權
• <aside> 相關資訊
• <nav> 導覽
Weblog Index
<div class=”entry”></div>
<div class=”entry”></div>
<div class=”entry”></div>
Weblog Index
<article></article>
<article></article>
<article></article>
<article>
• 部落格文章• 訪客留言• 討論區文章• 報章雜誌文章• ...etc
An Article<h1></h1>
<p></p>
<h2></h2>
<p></p>
<h2></h2>
<p></p>
<section>
</section>
An Article<h1></h1>
<p></p>
<h2></h2>
<p></p>
<h2></h2>
<p></p>
<hgroup><hgroup> <h1>My Weblog</h1> <h2 class="tagline">A lot of effort went into making this effortless.</h2></hgroup>
<div class="entry"> <h2>Travel day</h2></div>
<div class="entry"> <h2>I'm going to Prague!</h2></div>
http://diveintohtml5.org/semantics.html
Outline
• My Weblog
• Travel day
• I'm going to Prague!
http://diveintohtml5.org/semantics.html
Site Title and Article Title<h1>My Weblog</h1><h2 class="tagline">A lot of effort went into making this effortless.</h2>
<div class="entry"> <h2>Travel day</h2></div>
<div class="entry"> <h2>I'm going to Prague!</h2></div>
http://diveintohtml5.org/semantics.html
Outline
• My Weblog
• A lot of effort went into making this effortless
• Travel day
• I'm going to Prague!
http://diveintohtml5.org/semantics.html
Mixin
• Is <article> in <article> valid ?
• Is <article> in <section> valid ?
• How about <header> in <article> ?
Yes<article> <header> <h1>The Very First Rule of Life</h1> <p><time pubdate datetime="2009-10-09T14:28-08:00"></time></p> </header> <p>If there's a microphone anywhere near you, assume it's hot and sending whatever you're saying to the world. Seriously.</p> <p>...</p> <section> <h1>Comments</h1> <article> <footer> <p>Posted by: George Washington</p> <p><time pubdate datetime="2009-10-10T19:10-08:00"></time></p> </footer> <p>Yeah! Especially when talking about your lobbyist friends!</p> </article> </section></article>
http://dev.w3.org/html5/spec/sections.html#the-article-element
<article>
</article>
<header>
</header>
<p>Centent</p>
<section>
</section>
<h1>Title</h1>
<p><time pubdate></p>
<h1>Comments</h1>
<article>
</article>
<footer>
</footer>
<p></p>
<p>Posted by</p>
<p><time pubdate></p>
New Elements
<figure>
<figcaption>
for
http://html5doctor.com/the-figure-figcaption-elements/
Actually for
• Everything
• image
• code
• blockquote
• video
• ...etc
Examples
<figure> <img src="bubbles-work.jpeg" alt="Bubbles, sitting in his office chair, works on his latest project intently."> <figcaption>Bubbles at work</figcaption></figure>
http://dev.w3.org/html5/spec/grouping-content.html#the-figure-element
Examples
<figure> <p>'Twas brillig, and the slithy toves<br> Did gyre and gimble in the wabe;<br> All mimsy were the borogoves,<br> And the mome raths outgrabe.</p> <figcaption><cite>Jabberwocky</cite> (first verse). Lewis Carroll, 1832-98</figcaption></figure>
http://dev.w3.org/html5/spec/grouping-content.html#the-figure-element
And...
<audio>
<video>
<canvas>
<embed>
<dialog>
• dropped !
New Inline Elements
<b>, <i>, <small>
<ruby>, <rt>, <rp>
<mark>
<time>
<a>
b, i, small redefine
• <b> for typographic presentation is boldened
• <i> for alternate voice or mood
• <small> for small print
<ruby>
not on Rails
漢字かん じ
Ruby Markup
<ruby> 漢 <rt> かん </rt> 字 <rt> じ </rt></ruby>
http://dev.w3.org/html5/spec/text-level-semantics.html#the-ruby-element
<rp>
<ruby> 漢 <rp>(</rp><rt>かん</rt><rp>)</rp> 字 <rp>(</rp><rt>じ</rt><rp>)</rp></ruby>
漢 (かん) 字 (じ)http://dev.w3.org/html5/spec/text-level-semantics.html#the-rp-element
<mark>
畫重點
mark usage
• 引言重點• 程式碼重點• 搜尋結果關鍵字 highlight
• ...etc
Example
<p lang="en-US">Consider the following quote:</p><blockquote lang="en-GB"> <p>Look around and you will find, no-one's really <mark>colour</mark> blind.</p></blockquote><p lang="en-US">As we can tell from the <em>spelling</em> of the word,the person writing this quote is clearly not American.</p>
http://dev.w3.org/html5/spec/text-level-semantics.html#the-mark-element
<time>
日期時間
Example
<time datetime="2006-09-23">a Saturday</time><time pubdate datetime="2009-08-30">today</time>
http://dev.w3.org/html5/spec/text-level-semantics.html#the-time-element
Annoying pubdate
• without pubdate : just a time
• with pubdate : page publish time
• with pubdate and inside an <article> :article’s publish time
<a>
• block level link howto ?
• XHTML 2 :
• href is global level attribute
• HTML5 ?
Block Level Link in HTML5
<a href="http://blog.othree.net"> <p>I'm block. But I always try to be a link too.</p> <p>me too.</p></a>
a { display: block;}
Content Models
http://dev.w3.org/html5/spec/content-models.html#flow-content
Microdata
Remember Microformats ?
<div class="vcard"> 我是 <span class="fn">Bob Smith</span>, 不過朋友都叫我 <span class="nickname">Smithy</span>。 以下是我的首頁網址: <a href="http://www.example.com" class="url">www.example.com</a>. 我住在 Albuquerque (NM),目前服務於 <span class="org">ACME Corp</span>., 擔任<span class="title">工程師</span>一職。</div>
http://www.google.com/support/webmasters/bin/topic.py?topic=21997
Microdata
<div itemscope itemtype="http://data-vocabulary.org/Person"> 我是 <span itemprop="name">Bob Smith</span> 不過朋友都叫我 <span itemprop="nickname">Smithy</span>. 以下是我的首頁網址: <a href="http://www.example.com" itemprop="url">www.example.com</a> 我住在 Albuquerque (NM),擔任 <span itemprop="title">工程師</span> 一職 目前服務於 <span itemprop="affiliation">ACME Corp</span>。</div>
http://www.google.com/support/webmasters/bin/topic.py?topic=21997
attributes
• itemscope : 資料範圍
• itemtype : 資料類別
• itemprop : 資料屬性
APIs
• document . getItems( [ types ] )
• element . properties
• element . itemValue [ = value ]
http://www.w3.org/TR/2010/WD-microdata-20100624/#microdata-dom-api
No Browser Supports Now
Web Forms 2.0
Where is 1.0 ?
http://www.w3.org/TR/html401/
HTML 4.01 Spec
What’s New
• New Input Types
• New Attributes
• Form Validation
New Input Types
url
tel
number
range
color
date
<input type="datetime" /><input type="number" min="99" max="101"/><input type="email" placeholder="[email protected]" />
DEMOhttp://miketaylr.com/pres/html5/forms2.html
And One More Type
search
New Form Elements
<output>
<datalist>
<output>
<form> <input name=a type=number step=any> + <input name=b type=number step=any> = <output onforminput="value = a.valueAsNumber + b.valueAsNumber"></output></form>
http://dev.w3.org/html5/spec/the-button-element.html#the-output-element
<datalist>
<input type="search" autofocus list="search-suggestions"/><datalist id="search-suggestions"> <option label="DM" value="Depeche Mode"> <option label="Moz" value="Morrissey"> <option label="NO" value="New Order"> <option label="TC" value="The Cure"></datalist>
http://miketaylr.com/pres/html5/forms2.html
New Attributes
• autofocus: auto focus
• autocomplete: browser’s auto complete
• placeholder: short hint
• multiple for [type=file]: upload multiple file
Validation
• support new input types
• pattern attribute for <input>
• novalidate attribute for <form>
Opera Supportshttp://www.opera.com/docs/specs/presto26/
<datagrid>
• dropped !
Q&A