<?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>Hiro技术站 &#187; HTML</title>
	<atom:link href="http://www.ihiro.org/tag/html/feed" rel="self" type="application/rss+xml" />
	<link>http://www.ihiro.org</link>
	<description></description>
	<lastBuildDate>Fri, 06 Jan 2012 07:58:05 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3</generator>
		<item>
		<title>HTML:编写干净的且富有语义的html代码</title>
		<link>http://www.ihiro.org/coding-clean-and-rich-semantic-html</link>
		<comments>http://www.ihiro.org/coding-clean-and-rich-semantic-html#comments</comments>
		<pubDate>Mon, 30 Nov 2009 03:44:08 +0000</pubDate>
		<dc:creator>Hiro</dc:creator>
				<category><![CDATA[CSS、XHTML]]></category>
		<category><![CDATA[前端工程译文]]></category>
		<category><![CDATA[HTML]]></category>
		<category><![CDATA[前端工程]]></category>
		<category><![CDATA[译文]]></category>

		<guid isPermaLink="false">http://www.ihiro.org/?p=845</guid>
		<description><![CDATA[<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/cleaner-coding.gif" alt="cleaner-coding" title="cleaner-coding" width="100" height="100" class="alignleft size-full wp-image-855" />
<p>如果你是一个使用div标签做任何事的家伙，那么这篇文章将对你十分有益。该问重点讲述了如何通过使用富有语义的标签和最少的div标记来编写干净的html代码。你是否曾经也试图去修改别人的一些html模板，那么你一定会被代码里那些肮脏的标签所抓狂。编写干净的html代码，不仅对你自己有益，而且对你的团队也有益。他将大大地节约了你的开发与错误调试时间（特别是比较大的一些项目）。</p>
<p>1.尽可能少地使用div标签；<br />
2.使用div标签来控制页面的整体布局，如头部，内容部，侧边栏，底部等；<br />
3.内容必须包含在对应的语义标签内，而不是包含在div内；<br />
4.格式化你的源代码并且在结束标签处给出对应的注释语言。</p>
<p>该文翻译自：<a href="http://www.webdesignerwall.com/tutorials/coding-clean-and-semantic-templates/" rel="external">WebDesignWall: Coding Clean and Semantic Templates</a></p>]]></description>
			<content:encoded><![CDATA[<p>如果你是一个使用div标签做任何事的家伙，那么这篇文章将对你十分有益。该问重点讲述了如何通过使用富有语义的标签和最少的div标记来编写干净的html代码。你是否曾经也试图去修改别人的一些html模板，那么你一定会被代码里那些肮脏的标签所抓狂。编写干净的html代码，不仅对你自己有益，而且对你的团队也有益。他将大大地节约了你的开发与错误调试时间（特别是比较大的一些项目）。</p>
<h3>1.去除不必要的div标签：</h3>
<p>我曾经看到好多的人将form和ul标签都包含在了div标签内。为什么要写一个不必要的标签呢。你可以给适当的选择器赋予css规则，这样也可以达到同样的效果。</p>
<h4>例子一：</h4>
<p>下面的列子将展示给你如何删除多余的div标签，而将css规则声明给内部的form标签。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_01_div-form.gif" alt="clean_html_01_div-form" title="clean_html_01_div-form" width="470" height="259" class="aligncenter size-full wp-image-846" /></p>
<h4>例子二：</h4>
<p>有时侯我们会将一些内容用额外的div标签包含起来，其目的是为了严格地控制布局的空隙。在这个例子的左边使用了一个&lt;div class=”box”&gt;来控制两个box之间的外边距margin。但如果每个box内都有一个标题h4，那么我们可以通过h4标签来控制外间距margin，从而可以删除掉多余的&lt;div class=”box”&gt;标签。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_02_div-sidebox.gif" alt="clean_html_02_div-sidebox" title="clean_html_02_div-sidebox" width="470" height="267" class="aligncenter size-full wp-image-847" /></p>
<h3>2.使用富有语义的标记：</h3>
<p>你必须时刻都使用富有语义的标记来编写html代码（如：h1用作标题，p用作文章段落，ul则用于列表项）。那么，即使你的css文件没有引入或者没有被支持，你的html文档看起来也是富有意义的。</p>
<h4>例子：</h4>
<p>下面的一张图片比较了使用div标记和使用富有语义的标记编写的一段html代码（没有css代码的支持）在浏览器中编译后的效果。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_03_semantic-markups.gif" alt="clean_html_03_semantic-markups" title="clean_html_03_semantic-markups" width="470" height="482" class="aligncenter size-full wp-image-848" /></p>
<h3>3.尽可能地少使用div标签：</h3>
<p>你是否看到过一些到处都是div的html文档，它是否让你非常地抓狂？是否你曾忘记关闭一个&lt;/div&gt;或者无意添加了一个打开的&lt;div&gt;标签呢？我确定绝大多数的开发者都曾有过这样的经验。所以你需要尽可能少地使用div标签。这样以后的调试和改错的过程就会变得更加容易。</p>
<h4>例子一：</h4>
<p>用p标签来替代div标签去包含一个面包屑导航。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_04_div-breadcrumb.gif" alt="clean_html_04_div-breadcrumb" title="clean_html_04_div-breadcrumb" width="470" height="130" class="aligncenter size-full wp-image-849" /></p>
<h4>例子二：</h4>
<p>下面的例子展示了如何通过css规则来将两个div标签替换成一个span标签。这两种写法得到的结果是完全一致的。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_05_div-date.gif" alt="clean_html_05_div-date" title="clean_html_05_div-date" width="470" height="500" class="aligncenter size-full wp-image-850" /></p>
<h3>4.格式化（缩进）你的代码：</h3>
<p>你在开发的过程中始终要格式化你的源代码（如缩进嵌套的标签），这样的可以方便以后的阅读和错误调试。如果你使用Adobe Dreamweaver的话，那么你可以很简单地去格式化源代码。方法：点击“命令”菜单下的“应用源代码”选项即可。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_06_format-code.gif" alt="clean_html_06_format-code" title="clean_html_06_format-code" width="470" height="203" class="aligncenter size-full wp-image-851" /></p>
<h3>5.在&lt;/div&gt;结束处给出相应的注释：</h3>
<p>当你编写一个平台模板(如：Wordpress主题)代码时，这些模板文件会被分割成多个不同的文件：如：index.php, header.php, sidebar.php, 和 footer.php。因此，你必须在&lt;/div&gt;结束处给出相应的注释。比如：当我看到&lt;/div&gt;&lt;!&#8211; /wrapper &#8211;&gt;时，我就知道这里是&lt;div id=”wrapper”&gt;标签的结束处。<img src="http://www.ihiro.org/blog/wp-content/uploads/2009/11/clean_html_07_comment-code.gif" alt="clean_html_07_comment-code" title="clean_html_07_comment-code" width="470" height="122" class="aligncenter size-full wp-image-852" /></p>
<h3>总结：</h3>
<p>1.尽可能少地使用div标签；<br />
2.使用div标签来控制页面的整体布局，如头部，内容部，侧边栏，底部等；<br />
3.内容必须包含在对应的语义标签内，而不是包含在div内；<br />
4.格式化你的源代码并且在结束标签处给出对应的注释语言。</p>
<p>该文翻译自：<a href="http://www.webdesignerwall.com/tutorials/coding-clean-and-semantic-templates/" rel="external">WebDesignWall: Coding Clean and Semantic Templates</a></p>
<h2  class="related_post_title">你也许会喜欢阅读这些：</h2><ul class="related_post"><li>2010年03月15日 -- <a href="http://www.ihiro.org/uncovering-jquerys-hidden-features" title="jQuery:揭露jQuery的隐藏功能">jQuery:揭露jQuery的隐藏功能</a> (5)</li><li>2010年03月8日 -- <a href="http://www.ihiro.org/css3-basic" title="CSS:CSS3基础（附图）">CSS:CSS3基础（附图）</a> (12)</li><li>2010年01月22日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-2" title="jQuery:1.4新版本中你应该知道的15个新特性(二)">jQuery:1.4新版本中你应该知道的15个新特性(二)</a> (7)</li><li>2010年01月20日 -- <a href="http://www.ihiro.org/jquery-1-4-released-the-15-new-features-you-should-know-1" title="jQuery:1.4新版本中你应该知道的15个新特性(一)">jQuery:1.4新版本中你应该知道的15个新特性(一)</a> (6)</li><li>2009年12月18日 -- <a href="http://www.ihiro.org/10-javascript-tips" title="Javascript:10个Javscript编程的技巧">Javascript:10个Javscript编程的技巧</a> (4)</li><li>2012年01月6日 -- <a href="http://www.ihiro.org/xslt-get-the-first-last-name" title="XSLT:通过间隔符获取英文名的First Name和Last Name">XSLT:通过间隔符获取英文名的First Name和Last Name</a> (3)</li><li>2011年04月20日 -- <a href="http://www.ihiro.org/css3-transition" title="CSS3:Transition属性详解">CSS3:Transition属性详解</a> (82)</li><li>2011年04月1日 -- <a href="http://www.ihiro.org/html5-reading-note-chp4-canvas" title="HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas">HTML5:《HTML5. Up and Running》读书笔记.Chp4.Canvas</a> (22)</li><li>2011年03月21日 -- <a href="http://www.ihiro.org/html5-reading-note-chp3-elements" title="HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements">HTML5:《HTML5. Up and Running》读书笔记.Chp3.Elements</a> (24)</li><li>2011年03月15日 -- <a href="http://www.ihiro.org/html5-reading-note-chp2-features" title="HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features">HTML5:《HTML5. Up and Running》读书笔记.Chp2.Features</a> (23)</li></ul>]]></content:encoded>
			<wfw:commentRss>http://www.ihiro.org/coding-clean-and-rich-semantic-html/feed</wfw:commentRss>
		<slash:comments>13</slash:comments>
		</item>
	</channel>
</rss>
<!-- WP Super Cache is installed but broken. The path to wp-cache-phase1.php in wp-content/advanced-cache.php must be fixed! -->
