<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Silentash-默尘 &#187; html5</title>
	<atom:link href="http://blog.silentash.com/tag/html5/feed" rel="self" type="application/rss+xml" />
	<link>http://blog.silentash.com</link>
	<description>尘埃默默，风雨洗礼</description>
	<lastBuildDate>Tue, 24 Aug 2010 16:31:08 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>html5 doctype与图片多余空白</title>
		<link>http://blog.silentash.com/2010/01/html5-doctype-and-img-space/?fuckgfw</link>
		<comments>http://blog.silentash.com/2010/01/html5-doctype-and-img-space/?fuckgfw#comments</comments>
		<pubDate>Fri, 08 Jan 2010 09:28:26 +0000</pubDate>
		<dc:creator>nunumick</dc:creator>
				<category><![CDATA[Browser Bug]]></category>
		<category><![CDATA[WEB标准]]></category>
		<category><![CDATA[XHTML/CSS]]></category>
		<category><![CDATA[doctype]]></category>
		<category><![CDATA[html5]]></category>
		<category><![CDATA[img]]></category>
		<category><![CDATA[space]]></category>
		<category><![CDATA[图片空白]]></category>
		<category><![CDATA[文档类型]]></category>

		<guid isPermaLink="false">http://www.silentash.com/blog/?p=263</guid>
		<description><![CDATA[使用 html5 的 doctype 代替很长很长的 xhtml doctype 似乎成了时尚和趋势，只需写寥寥几个字符：
<code>&#60;!DOCTYPE html&#62;</code>
简单易用，而且兼容性又不错，不过毕竟IE7和IE6还是不认识它，就会出问题…
]]></description>
			<content:encoded><![CDATA[<p>使用 html5 的 doctype 代替很长很长的 xhtml doctype 似乎成了时尚和趋势，只需写寥寥几个字符：</p>
<pre class="chili"><code class="html">&lt;!DOCTYPE html&gt;
</code></pre>
<p>简单易用，而且兼容性又不错，不过毕竟IE7和IE6还是不认识它，就会出问题……</p>
<p>假设我们需要纵向排列几张图片，使用 table 排（不符合语义，不过总会用到），或者用 Div 排版，用之前的 doctype。</p>
<pre class="chili"><code class="html">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
&lt;html&gt;
    &lt;head&gt;
        &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=gb2312&quot; /&gt;
        &lt;style type=&quot;text/css&quot;&gt;
            table{border-collapse:collapse;border-spacing:0;}
            div,table{background:#fc0;}/*加点颜色看的更清楚鸟*/
        &lt;/style&gt;
    &lt;/head&gt;
    &lt;body&gt;
        &lt;!-- 图片和容器之间没有多余空格和换行符 --&gt;
        &lt;h3&gt;table排版&lt;/h3&gt;
        &lt;table cellspacing=&quot;0&quot; cellpadding=&quot;0&quot; border=&quot;0&quot;&gt;
            &lt;tr&gt;&lt;td&gt;&lt;img src=&quot;img.png&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
            &lt;tr&gt;&lt;td&gt;&lt;img src=&quot;img.png&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
            &lt;tr&gt;&lt;td&gt;&lt;img src=&quot;img.png&quot; /&gt;&lt;/td&gt;&lt;/tr&gt;
        &lt;/table&gt;
        &lt;h3&gt;div排版&lt;/h3&gt;
        &lt;div&gt;&lt;img src=&quot;img.png&quot; /&gt;&lt;/div&gt;
        &lt;div&gt;&lt;img src=&quot;img.png&quot; /&gt;&lt;/div&gt;
        &lt;div&gt;&lt;img src=&quot;img.png&quot; /&gt;&lt;/div&gt;
    &lt;/body&gt;
&lt;/html&gt;
</code></pre>
<p>很好，兼容所有浏览器，Demo ：<a href="http://www.silentash.com/uploads/201001/doctype-xhtml.html" target="_blank">xhtml doctype</a></p>
<p>OK,切换 doctype</p>
<pre class="chili"><code class="html">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Transitional//EN&quot;
&quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd&quot;&gt;
</code></pre>
<p>to</p>
<pre class="chili"><code class="html">&lt;!DOCTYPE html&gt;
</code></pre>
<p>再打开页面瞧瞧，<strong>除IE7和IE6，其他支持 HTML5 的浏览器都在图片与容器之间出现了多余空白</strong>，DEMO：<a href="http://www.silentash.com/uploads/201001/doctype-html5.html" target="_blank">html5 doctype</a><br />
不管哪些浏览器解析更正确，这总算是兼容性问题，需要统一表现。</p>
<p>如同我们解决常规 xhtml doctype 下的图片多余空白( <a href="http://www.silentash.com/uploads/201001/img-broke.html" target="_blank">Bug重现DEMO</a> )，方法毛多类～</p>
<p><strong>1.猥琐法</strong><br />
    (1)设置容器font-size或line-height (如果容器内有文字就惨了)</p>
<pre class="chili"><code class="css">div,table td{font:0/0 airal}
</code></pre>
<p>    (2)设置容器高度，然后溢出隐藏=.=!(td设置overflow不是很靠谱，所以这方法是猥琐中的极品)</p>
<pre class="chili"><code class="css">div,table td{height:80px;overflow:hidden}
</code></pre>
<p><strong>2.中庸法</strong><br />
    (1)设置图片的display属性 （单图片还行，多图横排就不靠谱了）</p>
<pre class="chili"><code class="css">img{display:block}
</code></pre>
<p>    (2)设置图片浮动属性 （原理虽一样，不过比上面靠谱）</p>
<pre class="chili"><code class="css">img{float:left}
</code></pre>
<p><strong>3.靠谱法</strong><br />
    (only 1)设置图片的对齐方式</p>
<pre class="chili"><code class="css">img{vertical-align:bottom}/*or bottom top and so on*/
</code></pre>
<p>几种方法组合起来会更靠谱，视情况而定！</p>
<p></p>
<h3>思考：Style Reset</h3>
<p>以下是<a href="http://html5doctor.com" target="_blank" >html5doctor.com</a>给出的<a href="http://html5doctor.com/html-5-reset-stylesheet/" target="_blank" >HTML5 Reset Stylesheet</a></p>
<pre class="chili"><code class="css">/*
html5doctor.com Reset Stylesheet
v1.4
2009-07-27
Author: Richard Clark - http://richclarkdesign.com
*/

html, body, div, span, object, iframe,
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
abbr, address, cite, code,
del, dfn, em, img, ins, kbd, q, samp,
small, strong, sub, sup, var,
b, i,dl, dt, dd, ol, ul, li,
fieldset, form, label, legend,
table, caption, tbody, tfoot, thead, tr, th, td,
article, aside, dialog, figure, footer, header,
hgroup, menu, nav, section,
time, mark, audio, video {
    margin:0;
    padding:0;
    border:0;
    outline:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}
body {
    line-height:1;
}
article, aside, dialog, figure, footer, header,
hgroup, nav, section {
    display:block;
}
nav ul {
    list-style:none;
}
blockquote, q {
    quotes:none;
}
blockquote:before, blockquote:after,
q:before, q:after {
    content:&#039;&#039;;
    content:none;
}
a {
    margin:0;
    padding:0;
    border:0;
    font-size:100%;
    vertical-align:baseline;
    background:transparent;
}
ins {
    background-color:#ff9;
    color:#000;
    text-decoration:none;
}
mark {
    background-color:#ff9;
    color:#000;
    font-style:italic;
    font-weight:bold;
}
del {
    text-decoration: line-through;
}
abbr[title], dfn[title] {
    border-bottom:1px dotted #000;
    cursor:help;
}
table {
    border-collapse:collapse;
    border-spacing:0;
}
hr {
    display:block;
    height:1px;
    border:0;
    border-top:1px solid #cccccc;
    margin:1em 0;
    padding:0;
}
input, select {
    vertical-align:middle;
}
</code></pre>
<p><strong>想法：加入 img Reset 是否会更靠谱?</strong></p>
<pre class="chili"><code class="css">img{vertical-align:middle}
</code></pre>
<h4>补充：</h4>
<p>正如<a href="http://dancewithnet.com/" target="_blank">秦歌</a>所说，不仅 html5 的 doctype 会引发此类问题，还有 html4.01 Strict ，这应该是标准与准标准之间的问题。也正因如此，我才把这篇文章同时归类为“WEB标准”。<br />
不管是哪个标准引发的，区别终归是区别，问题终归是问题，从这个表象我们至少可以得出结论：在 doctype 之间切换并不会一帆风顺，需要时刻小心，注意线上安全……在条件（结构及样式）成熟之后再做切换才最靠谱！</p>
<hr /><h2>Comments</h2><ul><li><a href="http://blog.silentash.com/2010/01/html5-doctype-and-img-space/?fuckgfw#comment-180">2010年01月15日</a>, <a href='http://www.chencheng.org/blog/2010/01/15/ppt-detail-on-html-spec/' rel='external nofollow' class='url'>陈成的博客 &mdash; 淘首页开发PPT详解 &mdash;&mdash; HTML规范</a> writes: [...] 理论上，标准模式和准标准模式的区别仅在于非IE6/7浏览器对于单元格里(原文说法可能有误，经测试所有图片均受影响)图片布局的不同处理。同事渔隐做了细致地测试并给出了解决方案。 [...]</li><li><a href="http://blog.silentash.com/2010/01/html5-doctype-and-img-space/?fuckgfw#comment-289">2010年03月3日</a>, <a href='http://www.isunlife.com/blog/index.php/archives/6/' rel='external nofollow' class='url'>Isunlife's Blog &raquo; 选择什么样的Doctype？</a> writes: [...] 在做一个口碑专题html的时候，问同事拿了一个模板，一下是模板源码： &lt;!doctype&nbsp;html&gt; &lt;html&gt; &lt;head&gt; &lt;meta&nbsp;http-equiv=&quot;Content-Type&quot;&nbsp;content=&quot;text/html;&nbsp;charset=gbk&quot;&nbsp;/&gt; &lt;title&gt;专题名字-口碑网&lt;/title&gt; &lt;meta&nbsp;name=&quot;Keywords&quot;&nbsp;content=&quot;需要填写关健字...&quot;&nbsp;/&gt; &lt;meta&nbsp;name=&quot;Description&quot;&nbsp;content=&quot;需要填写描述，110个字符之内...&quot;&nbsp;/&gt; &lt;meta&nbsp;http-equiv=&quot;X-UA-Compatible&quot;&nbsp;content=&quot;ie=Edge&quot;&nbsp;/&gt; &lt;link&nbsp;rel=&quot;stylesheet&quot;&nbsp;type=&quot;text/css&quot;&nbsp;href=&quot;http://k.kbcdn.com/global/base/base_4_2_20.css&quot;&nbsp;/&gt; &lt;style&gt; /*这里直接写样式*/ &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;div&nbsp;class=&quot;yui-d0f&quot;&gt; &lt;script&nbsp;src=&quot;http://www.koubei.com/CMS/headers/wrap/js_header.jsp?withCss=1&amp;type=mini&quot;&nbsp;type=&quot;text/javascript&quot;&nbsp;charset=&quot;gbk&quot;&gt;&lt;/script&gt; &lt;/div&gt; &lt;!--content--&gt; &lt;div&nbsp;class=&quot;yui-d0f&quot;&gt; &lt;div&nbsp;class=&quot;yui-d2f&quot;&gt; &lt;/div&gt; &lt;/div&gt; &lt;!--content&nbsp;end--&gt; &lt;div&nbsp;class=&quot;yui-d2f&quot;&gt;&lt;script&nbsp;type=&quot;text/javascript&quot;&nbsp;src=&quot;http://www.koubei.com/CMS/headers/new/js_footer.jsp&quot;&nbsp;charset=&quot;gbk&quot;&gt;&lt;/script&gt;&lt;/div&gt; &lt;!--script&nbsp;src=&quot;http://k.kbcdn.com/global/utilities/utilities_1_4_8.js&quot;&gt;&lt;/script--&gt; &lt;/body&gt; &lt;/html&gt; 其中第一行是这么写的：然后依次看了下口碑，淘宝，阿里，支付宝，阿里软件，阿里妈妈，百度，新浪，搜狐，Google，Yahoo等其中口碑，淘宝，支付宝，阿里，百度，Google的list页面，均使用新浪，搜狐，阿里妈妈，阿里软件，Yahoo等没有使用，淘宝和支付宝均在今年改版为似乎一时成了最流行的写法，简单，而且兼容性也不错。便更深入的了解了下doctype1.什么是DOCTYPEDOCTYPE是document type(文档类型)的简写，要建立符合标准的网页，DOCTYPE声明是必不可少的关键组成部分；在页面中，用来指定页面所使用的XHTML（或者HTML）的版本。要想制作符合标准的页面，一个必不可少的关键组成部分就是DOCTYPE声明。只有确定了一个正确的DOCTYPE，XHTML里的标识和CSS才能正常生效。参考文章：1.三七的用doctype激活浏览器模式 原文Activating Browser Modes with Doctype2.新首页开发PPT详解 —— HTML规范3.html5 doctype与图片多余空白4.Doctype和渲染模式对照表 [...]</li><li><a href="http://blog.silentash.com/2010/01/html5-doctype-and-img-space/?fuckgfw#comment-299">2010年03月5日</a>, <a href='http://varnow.org/?p=249' rel='external nofollow' class='url'>HTML优化 @ Miller</a> writes: [...] DOCTYPE对于页面展现非常重要，浏览器会根据具体的DOCTYPE来决定如何显示页面，除非你对删除DOCTYPE后的页面展示十分有把握，否则不要轻易删除。另外一种可行的方式是采用HTML5中的写法，即&lt;!doctype html&gt;，大多数浏览器能够将这种doctype写法解析为标准或准标准(Almost Standard)模式，不过依然会造成一些问题，具体见这里。目前百度、Google都是这么做的。 [...]</li><li><a href="http://blog.silentash.com/2010/01/html5-doctype-and-img-space/?fuckgfw#comment-466">2010年05月7日</a>, <a href='http://www.shejike.com/html-code-for-the-fine-optimization/' rel='external nofollow' class='url'>HTML代码之细微优化 &ndash; 设计客</a> writes: [...] DOCTYPE对于页面展现非常重要，浏览器会根据具体的DOCTYPE来决定如何显示页面，除非你对删除DOCTYPE后的页面展示十分有把握，否则不要轻易删除。另外一种可行的方式是采用HTML5中的写法，即，大多数浏览器能够将这种doctype写法解析为标准或准标准(Almost Standard)模式，不过依然会造成一些问题，具体见这里。目前百度、Google都是这么做的。 [...]</li><li><a href="http://blog.silentash.com/2010/01/html5-doctype-and-img-space/?fuckgfw#comment-756">2010年08月25日</a>, <a href='http://blog.silentash.com/2010/08/elements-hover-in-quirks-mode/' rel='external nofollow' class='url'>Silentash-默尘 &raquo; doctype与hover伪类</a> writes: [...] html5 doctype与图片多余空白 doctype对盒子模型的影响   doctype, hover, quirks mode, 文档类型  Address: [...]</li></ul><hr /><small>Copyright &copy; 2008-2010<br /> This feed is for personal, non-commercial use only. <br /> </small>]]></content:encoded>
			<wfw:commentRss>http://blog.silentash.com/2010/01/html5-doctype-and-img-space/?fuckgfw/feed</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
	</channel>
</rss>
