在图书馆看到这书,早就想拜读一下,考完了伟大的马哲,终于完成我的愿望啦。书的详细信息:http://www.china-pub.com/40160&ref=ps
书拿起来很薄,印刷还算精细。人民邮电出版出版的一系列书顺准都很高,但是翻译的质量参差不齐。这本书翻译质量不敢恭维,很多句子读起来绕口,我只有去查阅英文原版才得以豁然开朗。
原作者是Dan Cederholm,可能这名字没有Dave Shea这些顶级NB人士响亮,但是他的网站Simplebits.com很早就已经被我放到收藏夹里了。
整本书适合懂得XHTML,但是想让自己的页面更接近网页标准的设计师、前端工程师们细读。内容都不是什么新东西,但是算是一个比较实在的小册子。总的来说,是一本优秀的入门级读物。应该与一本《CSS Mastery》相似,大家两者只要收录其一就可以。
本文是我整理的阅读笔记,也是我觉得里面比较精华的内容,供大家参考。如果你发现这些内容已经是烂熟于心,这本书就远远低于你的要求了。(那一定是很N的人了,笑……)
I met this book in the library months ago. Despite the few glimpses in a hurry, I felt it was a great book and made up a mind to produce some time to read it.
Detail about this book:
http://astore.amazon.com/simplebits-20/detail/1590593812
It’s only a handy book, light and thin. The author is Dan Cederholm, who probably is a nobody in your mind but indeed an expert in Web Standards. Simplebits is his own site and I took it into my favorites long time ago.
On the whole, this book is good enough for those who know the basics about XHTML, but desire to rise into a upper atmosphere of web standards. You may think CSS Mastery is also anther choice. Yes, it’s very similar to CSS Mastery. In my opinion, just buy either of two.
Following are some my digests and thoughts about this book, for you review. Hope you find it useful.
列表元素
- 不要用br换行
- 保持标签闭合
- 使用li和ul
本节中作者讲述了用纯CSS实现一个非常漂亮的导航菜单,值得参考。
标题
- 使用h1~h6描述标题
- 注意标题级别,尽量做到递减
本节中描述一种名叫“变色龙效果(The Chameleon Effect)”的技巧。通过运用透明的GIF的IMG元素,并在CSS中设置IMG的background属性,这样可以为透明部分填色。
<h3><img src="http://images.fastcompany.com/icon/first_imp.gif"width="13"height="13"alt="*"/>FIRST IMPRESSION</h3>
仅仅通过更改CSS的属性可以达到更换颜色的目的。这种技巧也可以用来作图像的水影。
表格数据
table并不是万恶的,它是XHTML的一部分,表格型数据都应该用table来写,这些数据可能是:
- 日历
- 工作簿
- 图表
- 日程表
写表格时应该注意一些细节:
- 加入caption作为表格标题,明确表格内容
- 设置summary属性介绍table的内容,提高可访问性
- 活用th表示表头
- 利用td的headers属性表明数据之间的关系
- 在th中设置abbr属性设置该表头的简写或概要,为屏幕阅读器提供便利
- 活用thead、tfoot、tbody增加表格的语义;同时打印输出时,会在每一个单独的纸张上都输出thead和tfoot,提高可读性
本节中作者演示了如何用CSS创建基于表格的格点:
table{
border-top:1px solid#999;
border-left:1px solid#999;
border-collapse:collapse;
}
th,td{
border-right:1px solid#999;
border-bottom:1px solid#999;
}
这里我们通过设置border-collapse完全消除单元格之间的间隙。
引用文本
这方面是大多数设计师没有注意的问题了,作者也提出了一些网上常见的做法以及他们的缺点。正确的编写引用文本,应该:
- 用blockquote包围内容
- 给blockquote添加cite属性,告诉浏览器这段文字来自哪里
- 如果是行内引用则用q
- 给q设置lang标签(完整的lang属性可用值,参考http://www.w3.org/TR/html4/struct/dirlang.html#langcodes)
表单
又是XHTML的一大陷阱,看看高手写出来的表单代码和自己写的就觉得自己没学过XHTML。时常可以看到人们这样做:
- 用br换行
- 用table布局
- 使用p和br实现换行
书中是这样建议的:
- 对于简单的表单尽量不要用table
- 对于项目的名称,用label包围
- 简单的表单通过p、label就可以简单的构件
- 最极端的状态是用dl、dt、dd来写表单,这样的可读性是最高的
- 设置input等项目的tabindex属性,提高可用性
- 为常用项目设置accesskey属性
- 在同一个form下,利用fieldset给项目分组
- 利用legengd给每个fieldset提供标题
一些实例:
<form action="/path/to/script"id="thisform"method="post"> <dl> <dt><label for="name">Name:</label></dt> <dd><input type="text"id="name"name="name"/></dd> <dt><label for="email">Email:</label></dt> <dd><input type="text"id="email"name="email"/></dd> <dt><label for="remember">Remember this info?</label></dt> <dd><input type="checkbox"id="remember"name="remember"/></dd> <dt><input type="submit"value="submit"/></dt> </dl> </form>
个人的疑虑:这个写法中,dt和dd的个数不匹配,是否完全正确还有待研究。在HTML&XHTML The Definitive Guide中也只是模糊地这样说明:
each item name in a<dl>list is marked with the<dt>tag,followed by the item’s definition or explanation marked by the<dd>tag.
<form action="/path/to/script"id="thisform"method="post"> <p><label for="name"accesskey="9">Name:</label><br/> <input type="text"id="name"name="name"tabindex="1"/></p> <p><label for="email">Email:</label><br/> <input type="text"id="email"name="email"tabindex="2"/></p> <p><input type="checkbox"id="remember"name="remember" tabindex="3"/> <label for="remember">Remember this info?</label></p> <p><input type="submit"value="submit"tabindex="4"/></p> </form>
<form action="/path/to/script"id="thisform"method="post"> <fieldset> <legend>Sign In</legend> <p><label for="name"accesskey="9">Name:</label><br/> <input type="text"id="name"name="name"tabindex="1"/></p> <p><label for="email">Email:</label><br/> <input type="text"id="email"name="email"tabindex="2"/></p> <p><input type="checkbox"id="remember"name="remember" tabindex="3"/> <label for="remember">Remember this info?</label></p> <p><input type="submit"value="submit"tabindex="4"/></p> </fieldset> </form>
短语元素
这个也是极容易混淆的地方,面试前端,也许人家就会问你:“<b>和<strong>有什么区别?”
事实上目前实现富有语义的XHTML的最大困难就是设计师不愿意浪费时间来设定这些短语元素。
书中简明扼要的指出:
<em>表示强调
<strong>表示更强的强调
- <b>和<strong>在显示效果上都是粗体,但是<strong>能表达语义上的含义,而<b>仅仅进行了视觉上的格式化。当然,这些位置最好使用CSS的font-weight或font-style实现
- <i>和<em>和上面同理
Your order number for future reference is:<strong>6474-82071</strong>. It took me not one,but<em>three</em>hours to shovel my driveway this weekend.
只有上面这两种写法才能正确表示强调。当然不是要求你不用<b>和<i>,事实上有很多位置只需要对其进行视觉上的格式化。
<cite>用来表明引用信息或对其文献的参考说明。示例:
The novel,<cite>The Scarlet Letter</cite>is set in Puritan Boston and like this book,was written in Salem,Massachusetts.
- <abbr>表示一种简写形式,如WWW、HTTP等,屏幕阅读器将会将其以单个字母地形式读出
- <acronym>表示取首字母的缩写形式,屏幕阅读器将会将其作为一个单词读出
- 设置<abbr>和<acronym>的title属性定义其全称
- 虽然IE只支持<acronym>,但我们还是应该按照规范来写页面,该用什么用什么
<abbr title="eXtensible HyperText Markup Language">XHTML</abbr> <acronym title="North Atlantic Treaty Organization">NATO</acronym>
同时,你可能需要设置CSS来让某些不遵从标准的浏览器实现两者的默认行为:
abbr{
speak:spell-out;
}
acronym{
speak:normal;
}
用<code>来展示代码,示例:
<code>
#content{
width:80%;
padding:20px;
background:blue;
}
<samp>用于显示程序或脚本的运行输出结果
<p>When the script has executed,at the command line you will see the message<samp>script was successful!</samp>.</p>
<var>用于指明程序的变量或参数,示例:
<p>I'm going to pass the parameter<var>lastUpdated</var>to my main.xsl file.</p>
<kbd>用于指明那些需要有用户输入的文本,示例:
<p>To quickly change focus to the search input field,Mac users type<kbd>Command+9</kbd>.</p>
锚点
锚点是互联网中最基本的元素,它的产生出现可以追溯到Internet的第一张网页。
锚点的指向页面内部的一个元素,也可以指向网络上的任何一个URL。
当你需要让锚点指向页面内部元素的时候,你可以:
<p><a href="#orange">About Orange</a></p> ....... <h2 id="orange">Orange are tasty</h2>
如果你想设置一个指向头部的链接,你最好不要用"#top",因为top是一些浏览器的保留字段。
可能基于某些向前兼容的考虑,会使用name属性,例如:
<p><a href="#orange">About Orange</a></p> ....... <h2><a id="orange"name="orange">Orange are tasty</a></h2>
但不是每个元素都同时支持name和id属性——只有如下标签是支持的:
<a>、<applet>、<form>、<frame>、<iframe>、<img>、<map>
书中还给出了其他建议:
- 给链接一个title属性,写出该链接的提示文字
- 注意链接的全局样式
- 伪类:link可以帮你找到所有有href属性的链接
- 应该用CSS定义样式将链接突出
- 伪类的定义顺序必须是:link,:visited,:hover,:active,记忆诀窍是LoVe/HAte
更多关于列表
这一节作者主要讨论了更多形式的列表,比如有序列表和解释列表。
构造带序号的列表应该使用ol、li,浏览器会自动为li编号
可以定义li的list-style-type来改变编号的类型,可选值为:
- decimal:1,2,3,4,etc.(commonly the default)
- upper-alpha:A,B,C,D,etc.
- lower-alpha:a,b,c,d,etc.
- upper-roman:I,II,III,IV,etc.
- lower-roman:I,ii,iii,iv,etc.
- none:No numeral
注意,不要直接用ol的type属性来改变编号类型。
对于解释列表,我们可以用dl、dt、dd来描述,这样做的好处除了语义性强之外,在默认状态下就有很高的可读性。
<dl> <dt>CSS</dt> <dd>A simple mechanism for adding style(e.g.fonts,colors,spacing)to Web documents.</dd> <dt>XHTML</dt> <dd>A family of current and future document types and modules that reproduce,subset,and extend HTML,reformulated in XML.</dd> <dt>XML</dt> <dd>A simple,very flexible text format derived from SGML.</dd> </dl>
精简代码
对于CSS新手来说,随意给元素指定class、id会造成日后维护的困难,而且很容易因为CSS的继承而是你无法实现你想要的效果。作者给出了一些建议
- 不要滥用class
- 活用选择器来节约id、class
- 在单个元素,例如form、ul、blockquote等又套一层div是不可取的
Lists
- Don’t use br to break a line
- Keep the tag closed
- Use li with ul
In this chapter, Dan use pure css to create a beautiful navi tab, which may inspire you a lot.
Heading
- Use h1~h6 to describe headings
- Use them in the descending order
Here, we get to know The Chameleon Effect, which take advantages of transparent GIF in a IMG tag. When you change the background property of IMG in CSS, you change the background of the image the users will feel.
<h3><img src="http://images.fastcompany.com/icon/first_imp.gif"width="13"height="13"alt="*"/>FIRST IMPRESSION</h3>
See, you just change the background of a “image” through modification of CSS. This will work well when you want add a watermark on your photoes.
Tabular Data
Table is not evil, and it’s part of XHTMl Spec. Tabular data should be described by table tag, e.g:
- Calender
- Spreadsheet
- Charts
- Schedules
Do with more cautions:
- Add caption tag to serve as a title of the table
- Assign summary property to tell users the breif to the table, thus increasing the accessiblity.
- use th as cell heading
- use the headers property of td tag to show the relations among the data cell
- assign abbr property in th to brief the cell heading. This will help screen readers a lot
- Use thead, tfoot, tbody to make table more sematic. You will be glad to find table heading and table foot will be displayed on every printed talbes.
And the author shows us how to create a grid using table and CSS :
table{
border-top:1px solid#999;
border-left:1px solid#999;
border-collapse:collapse;
}
th,td{
border-right:1px solid#999;
border-bottom:1px solid#999;
}
Here we set the border-collpase to collpase the gag between cells.
Quotations
It’s a common pitfall to most designers. Dan lists some methods used widely and tell the goods and bads.
For correct quotations:
- Use blockquote to wrap the content
- Assign cite property to blockquote, telling us where the quotations come from
- Use q for inline quotations
- Assign lang property for q to tell users in which language the quotaions are (Complete list of the availible values for lang: http://www.w3.org/TR/html4/struct/dirlang.html#langcodes)
Form
Just another perilous pitfall. Good forms and bad ones differ tremendously.
Sometiems we find people write some like this:
- Use br to break a line
- Use table for layout
- Use both p and br to break a line
Dave suggests:
- Nerver use table for simple forms
- Wrap the title of input item with label tag
- Use p and label for simple forms
- For ultimate readablity, use dl, dt, dd to describe a forms
- Assign tabindex property for input tags and other interactable components
- Assign accesskey property for frequently used elements
- Use fieldset to group related form items
Some examples:
<form action="/path/to/script"id="thisform"method="post"> <dl> <dt><label for="name">Name:</label></dt> <dd><input type="text"id="name"name="name"/></dd> <dt><label for="email">Email:</label></dt> <dd><input type="text"id="email"name="email"/></dd> <dt><label for="remember">Remember this info?</label></dt> <dd><input type="checkbox"id="remember"name="remember"/></dd> <dt><input type="submit"value="submit"/></dt> </dl> </form>
In code above, dt and dd are not equally matched, which I doubtly personally. But I can’t prove this wrong as HTML&XHTML The Definitive Guide give only a dim definition:
each item name in a<dl>list is marked with the<dt>tag,followed by the item’s definition or explanation marked by the<dd>tag.
<form action="/path/to/script"id="thisform"method="post"> <p><label for="name"accesskey="9">Name:</label><br/> <input type="text"id="name"name="name"tabindex="1"/></p> <p><label for="email">Email:</label><br/> <input type="text"id="email"name="email"tabindex="2"/></p> <p><input type="checkbox"id="remember"name="remember" tabindex="3"/> <label for="remember">Remember this info?</label></p> <p><input type="submit"value="submit"tabindex="4"/></p> </form>
<form action="/path/to/script"id="thisform"method="post"> <fieldset> <legend>Sign In</legend> <p><label for="name"accesskey="9">Name:</label><br/> <input type="text"id="name"name="name"tabindex="1"/></p> <p><label for="email">Email:</label><br/> <input type="text"id="email"name="email"tabindex="2"/></p> <p><input type="checkbox"id="remember"name="remember" tabindex="3"/> <label for="remember">Remember this info?</label></p> <p><input type="submit"value="submit"tabindex="4"/></p> </fieldset> </form>
Phase Elements
These are confusing elements in HTML. You may encounter questions about these when you are applying for a front-end engineer:
“What’s the difference between <b> and <strong>?”
In fact, most designers are just reluctant commsuming time applying these seemingly insignificant phase elements.
But, these are the very important steps to build more semantic pages.
Dave points out:
<em> means emphasis
<strong> means stronger emphasis
- <b> and <strong> both make text bold,but <strong> convery a sematicly emphasizing meaning,while <b> only does the job of formatting visually。Of course you’d better to use font-weight and font-style other to make text bold or italic
- <i> and <em> are the same story.
Your order number for future reference is:<strong>6474-82071</strong>. It took me not one,but<em>three</em>hours to shovel my driveway this weekend.
Only the two methods above can show your intended emphasis.
<cite> is used to contain a citation or a reference to other sources, E.g :
The novel,<cite>The Scarlet Letter</cite>is set in Puritan Boston and like this book,was written in Salem,Massachusetts.
- <abbr>Indicates an abbreviated form (e.g., WWW, HTTP, URI, Mass., etc.)
- <acronym> Indicates an acronym (e.g., WAC, radar, etc.)
- Assign title properties for <abbr> and <acronym> to tell users the full name
- Although IE only support <acronym>,we cannot abandon the use of abbr and desert the will of web standards. Just mark the term up according to the specifications.
<abbr title="eXtensible HyperText Markup Language">XHTML</abbr> <acronym title="North Atlantic Treaty Organization">NATO</acronym>
There are also two CSS rules that could be added to an aural style sheet to further reinforce these directives:
abbr{
speak:spell-out;
}
acronym{
speak:normal;
}
The element is designed for demonstrating code examples within XHTML pages.
<code>
#content{
width:80%;
padding:20px;
background:blue;
}
<samp> is used to show sample output from programs and scripts.
<p>When the script has executed,at the command line you will see the message<samp>script was successful!</samp>.</p>
<var> is used to designate a program parameter or variable.
<p>I'm going to pass the parameter<var>lastUpdated</var>to my main.xsl file.</p>
<kbd> Indicates text to be entered by the user.
<p>To quickly change focus to the search input field,Mac users type<kbd>Command+9</kbd>.</p>
Anchors
Anchors are the soul of internet and they are the citizens since the birth of internet.
Anchors can be pointed to any URL on the web or any element inside the page. If you want to anchor directs to other part of the page:
<p><a href="#orange">About Orange</a></p> ....... <h2 id="orange">Orange are tasty</h2>
Don't use "top" as a value if you want to make a link that point to the "top" of the page because "top" is often the keyword in a browser.
Taking the compatiblilty issues into accounts, you'd like to use name property as well:
<p><a href="#orange">About Orange</a></p> ....... <h2><a id="orange"name="orange">Orange are tasty</a></h2>
However, not very elements has both name and id property like the following:
<a>、<applet>、<form>、<frame>、<iframe>、<img>、<map>
Dan also suggests:
- Assign title property whose value can be used in the tooltip when mouse over
- Beware of global link styling
- :link pseudo-class can find all the links that have href property
- You should always highlight the links among the text
- Ordering the four pseudo-classes mentioned becomes important in order for all of them to behave properly—without one overriding the other. The correct order - :link,:visited,:hover,:active. Maybe this will help you: LoVe/HAte
More on list
In this chapter, Dan pays more attentions to ordered list and definition list.
The browser will automatically number the li with demical number.
You can change the way thourgh list-style-type property:
- decimal:1,2,3,4,etc.(commonly the default)
- upper-alpha:A,B,C,D,etc.
- lower-alpha:a,b,c,d,etc.
- upper-roman:I,II,III,IV,etc.
- lower-roman:I,ii,iii,iv,etc.
- none:No numeral
Don't use the type property in a ol tag to alte the list style.
With definition list, we can use dl, dt, dd to describe it. You will get high readablity in default.
<dl> <dt>CSS</dt> <dd>A simple mechanism for adding style(e.g.fonts,colors,spacing)to Web documents.</dd> <dt>XHTML</dt> <dd>A family of current and future document types and modules that reproduce,subset,and extend HTML,reformulated in XML.</dd> <dt>XML</dt> <dd>A simple,very flexible text format derived from SGML.</dd> </dl>
Simplifing Markup
For novices, it's too easy to make another class in CSS which will eventually hinder job in the future as you've got too many class to maintaine.
Some suggestions:
- Use class wisely
- Use descendant selectors instead
- Wraping the lements like form, ul, blockquote with another div is not a wise decision








![[F5] Brisbane and Gold Coast Web Design, Development, Illustration and more... (20100729)](http://farm5.static.flickr.com/4120/4874414037_b26e7875d6_s.jpg)
One Trackback
[...] Robin CSS, Layout, XHTML Comments (0) Views(1) 2009 Jun 26 This post follows my earlier post Digest and Thoughts on Web Standards Solutions – Basic Markups. I suggest read that article first and then head to this [...]