Web Rebuild

36
WEB 重重 重重 , Taobao UED

description

网站重构初学者材料

Transcript of Web Rebuild

Page 1: Web Rebuild

WEB 重构渔隐 , Taobao UED

Page 2: Web Rebuild

了解 WEB 重构前需要知道的一些内容

Page 3: Web Rebuild

table

Page 4: Web Rebuild

The HTML table model allows authors to arrange data -- text, preformatted text, images, links, forms, form fields, other tables, etc. -- into rows and columns of cells.

http://www.w3.org/TR/html401/struct/tables.html#h-11.1

W3C :

Page 5: Web Rebuild

整理数据很方便

Page 6: Web Rebuild

Table 布局

Page 7: Web Rebuild

为何不建议用 table 布局?

Page 8: Web Rebuild

Tables should not be used purely as a means to layout document content as this may present problems when rendering to non-visual media. …To minimize these problems, authors should use style sheets to control layout rather than tables.

W3C :

Page 9: Web Rebuild

是表格而非栅格

Page 10: Web Rebuild

1. 不够语义 2. 维护性差3. 不利于搜索引擎优化4. 代码臃肿5. 可访问性差

Page 11: Web Rebuild

请不要排斥 tableTable 没有错,错的是拿 table 做布局的人

Page 12: Web Rebuild

Div 和 Span

Page 13: Web Rebuild

The DIV and SPAN elements, in conjunction with the id and class attributes, offer a generic mechanism for adding structure to documents. These elements define content to be inline (SPAN) or block-level (DIV) but impose no other presentational idioms on the content. Thus, authors may use these elements in conjunction with style sheets, the lang attribute, etc., to tailor HTML to their own needs and tastes.

http://www.w3.org/TR/html401/struct/global.html#h-7.5.4

Page 14: Web Rebuild

标签(结构) 语义 表现(样式)div 节元素,块容器 独立一行span 节元素,内联容器 无具体表现table 表格 很复杂p 段落 上下两端有边距a 超链接 蓝色、下划线strong 强调文本 粗体em 强调文本 斜体

每个 html 标签都有其特有含义

Page 15: Web Rebuild

WEB 重构:还标签本意,结构、表现、行为相分离

Page 16: Web Rebuild

在拿到设计稿时,首先应该考虑的不是表现,而是结构

标题

强调

列表

表格

表单

段落

Page 17: Web Rebuild

<h3> 标题 </h3><img /><h4> 小标题 </h4><p> 内容 </p> <ul> <li></li></ul><h3> 标题 </h3><table> 表格 </table><h3> 标题 </h3><fieldset> <form> <input /> </form></fieldset>

还原语义,从代码上理解网页

Page 18: Web Rebuild

基本 HTML 结构

Page 19: Web Rebuild

1.Html 版本信息—文档类型 (doctype)

2.Html 元素3. 文档头 head 标签4. 文档内容 body 标签

<!DOCTYPE html><html> <head> <title></title> </head> <body> </body></html>

Page 20: Web Rebuild

Doctype,Html,head,body 顺序固定且唯一

Page 21: Web Rebuild

Doctype 很不起眼,但很重要http://www.chencheng.org/blog/2010/01/15/ppt-detail-on-html-spec/

http://blog.silentash.com/2010/01/html5-doctype-and-img-space/

Page 22: Web Rebuild

好的结构是一切的基础

Page 23: Web Rebuild

<!DOCTYPE html><html> <head> <title> 文档标题 </title> </head> <body>

<h3> 标题 </h3><img /><h4> 小标题 </h4><p> 内容 </p> <ul> <li></li></ul><h3> 标题 </h3><table> 表格 </table><h3> 标题 </h3><fieldset> <form> <input /> </form></fieldset>

</body></html>

Page 24: Web Rebuild

分离表现<h3 style=“border:1px dashed #f00”> 标题 </h3>

to

<style> h3{ border:1px dashed #f00; }</style><h3> 标题 </h3>

Page 25: Web Rebuild

分离脚本<button onclick=“javascript:alert(‘hello world’)”>hello world</button>

to

<button id=“someid” >hello world</button><script> document.getElementById(‘someid’).onclick = function(){ alert(‘hello world’); }</script>

Page 26: Web Rebuild

<!DOCTYPE html><html> <head> <title> 文档标题 </title> <style> h3{color:#f00} </style> </head> <body>

<h3> 标题 </h3><img /><h4> 小标题 </h4><p> 内容 </p> <ul> <li></li></ul><h3> 标题 </h3><table> 表格 </table><h3> 标题 </h3><fieldset> <form> <input id=“someid” /> </form></fieldset><script> document.getElementById(‘someid’).onclick=function(){Some coding…}<script>

</body></html>

Page 27: Web Rebuild

将表现和脚本分离到外部文件

Page 28: Web Rebuild

<!DOCTYPE html><html> <head> <title> 文档标题 </title> <link type=“text/css” rel=“stylesheet” href=“style.css” /> </head> <body>

<h3> 标题 </h3><img /><h4> 小标题 </h4><p> 内容 </p> <ul> <li></li></ul><h3> 标题 </h3><table> 表格 </table><h3> 标题 </h3><fieldset> <form> <input id=“someid” /> </form></fieldset><script src=“code.js” type=“text/javascript” ></script>

</body></html>

Page 29: Web Rebuild

兼容性调整,前端开发赖以生存的基本技能

Page 30: Web Rebuild
Page 31: Web Rebuild

淘宝网用户浏览器分布图, 19 日摘自哈勃系统

Page 32: Web Rebuild

淘宝网用户屏幕分辨率分布图, 19 日摘自哈勃系统

Page 33: Web Rebuild

从浏览器趋势可以看出, IE6 虽逐步消亡,却依旧强势

Page 34: Web Rebuild

为用户而设计是设计师和前端开发共同的目标

Page 35: Web Rebuild

路漫漫其修远兮……

Page 36: Web Rebuild

THX!