网页编码指南
本指南包括文件结构,命名约定,设计和编码推荐,还有前端开发中常用到的样式和资源等。
1.0 编码标准
这个章节包含最基本的编码标准。
1.1 代码验证
页面基于由W3C(万维网联盟)拟定的XTHML 1.0 Transitional 和 CSS2.1标准。所有页面文件都应该遵循W3C标准。下面为推荐的代码校验工具。
1.2 文档类型(DOCTYPE)和名称空间(NAMESPACE)声明
统一使用XHTML 1.0的过渡标准
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
1.3 浏览器支持
在IE6.0,IE7.0以及Firefox(版本2.0以上)进行全面完整的测试,保证表现一致。其他浏览器提供基本的支持。
| 浏览器 |
支持级别 |
| IE 6+ |
全面支持 |
| Firefox 2.0以上 |
全面支持 |
| 其他浏览器 |
基本支持 |
1.4 文件编码
页面文件,CSS和JS文件均采用utf-8编码。页面文件需要在代码中声明utf-8编码。
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
1.5 标题,关键字和描述
在页面文件的Title、Keywords和Descriptions标签中添加文档的描述内容。
<title>2008年中国经济调控定调:货币政策可能从紧_资讯_凤凰网</title>
<meta name="keywords" content="经济调控,货币政策,凤凰网,凤凰新媒体">
<meta name="description" content="消息人士透露,文件报告的起草工作已经基本完成,按常规,中央经济工作会议即将召开,为2008年中国经济定调。">
1.6 图像增加ALT属性
文档内容图片需要在图片增加alt属性
<img src="http://img.mydomain.com/stock.jpg" alt="股市大涨">
如果图片用于修饰,则alt属性为空
<img src="http://img.mydomain.com/decoration.gif" alt="">
1.7 语义化标签
页面代码由附有语义的html代码组成,常见的语义代码包括
- h1, h2, h3, h4, h5, h6, h7
- strong, em
- ul, ol and dl
- caption, thead, tbody and tfoot
1.8 区块独立化编码
为便于重用,页面代码中各大区块样式相互独立。示例如下:
.listImage { position:relative; background:#fff;}
.listImage a { color:#454545;}
.listImage .head { position:relative; border:1px solid #fff;}
.listImage .head a { color:#fff;}
.listImage .head .more { position:absolute; right:5px; top:11px;}
.box .list { position: absolute; top:43px; left:200px; width:58%;}
.box .list ul { margin-right:10px; padding-left:5px;}
.box .list li { line-height:20px;}
.box .list ul.headline { background:#efefef; margin-top:8px;}
1.9 CSS命名约定
总体原则:
1. 采用骆驼命名法,英文单词第二个起使用大写,名称尽量使用英文,避免使用汉语拼音;
2. 不加中杠和下划线,英文单词最好在两个以内,而且尽量不缩写,除非一看就明白的单词;
3. 命名语义要清晰,而且尽量不要带有属性内容,如left,right,size这样的单词,例子:#left #right #size10等;
以下参考csser.org阿捷的文章http://www.csser.org/2006/03/css-name-specification/
| 区块名称 |
常用命名 |
区块名称 |
常用命名 |
区块名称 |
常用命名 |
| 总容器 |
container/wrapper |
页头 |
header/hd |
页尾 |
footer/ft |
| 页面主体 |
main |
内容 |
content |
搜索 |
search |
| 侧栏 |
sidebar |
菜单 |
menu |
子菜单 |
subMenu |
| 标志 |
logo |
广告 |
ad |
广告通栏 |
banner |
| 导航 |
nav |
子导航 |
subNav |
标签 |
tab |
| 信息 |
message |
提示 |
tip |
指南 |
guide |
| 新闻 |
news |
标题 |
title |
头条 |
headline |
| 最热 |
hot |
最新 |
new |
实时 |
realTime |
| 注册 |
register |
登录 |
signIn |
状态 |
status |
| 合作方 |
partner |
友情链接 |
friendLink |
版权 |
copyright |
| 列表 |
list |
视频 |
video |
调试 |
debug |
1.10 JavaScript命名约定
参考http://dojotoolkit.org/developer/StyleGuide
核心 API 请使用下面的风格:
| 结构 |
规则 |
示例 |
| 类 |
Pascal,所有单词首字母大写 |
EventHandler |
| 公有方法 |
camel,首字母小写 |
obj.doSomeThing() |
| 公有变量 |
camel,首字母小写 |
obj.someVariable |
| 常量 |
Pascal或者全部大写 |
MaxSize, MAXSIZE |
| 私有方法 |
混合命名 |
_doSomeThing() |
| 私有变量 |
混合命名 |
_someVariable |
| 方法参数 |
camel,首字母小写 |
function doSomeThing(someVariable,_someVariableTwo) |
常用命名:
- init:初始化对象
- close:结束执行
- start/stop:开始/停止某动作
- select:选取某元素
- indexOf:获取某元素在集合中的索引
- find:遍历查找时
- reset:重置
- on**:当发生某种情况时,如onError
- get**:获取某种数据,如getXml,getHotKeywords
- set**:设置数据,setKeywords
- parse**:分析某种数据,如parseDocument
- render**:输出数据时,如renderHtml
- clear**:清除相关数据,clearStyle
- reg**:某正则表达式
- is***:某boolean变量
2.0 CSS编码实践
这个章节包含CSS样例代码。
2.1 超链接样式
- 与背景图结合表现
外部链接
点击查看代码
<style>
a.external { background:url(externalLink.gif) no-repeat top right; padding-right:10px;}
a.comment { background:url(comment.gif) no-repeat top left; padding-left:15px;}
</style>
<a href="#" class="external">外部链接</a>
<a href="#" class="comment">用户评论</a>
- 设置为块级标签获得宽高属性
点击查看代码
<style>
h3.title { border-top:1px solid #B0B0B0; font-size:14px;}
h3.title a{ display:block; height:35px; line-height:35px; border-top:1px solid #fff;color:#666;background:#F7F2D9 url(document.gif) no-repeat bottom left;padding-left:40px;}
</style>
<h3 class="title"><a href="#">李辉获奖感言:在历史的寻找中感悟人生</a></h3>
- 用文本缩进隐藏文字链接
点击查看代码
<style>
#header-digg { height:40px;background:url(diggHeader.gif) no-repeat left center;}
#header-digg .homeLink { display:block; width:100px; height:40px; text-indent:-2000em; }
#header-digg .homeLink em {visibility:hidden}
#header-digg .homeLink:hover { text-decoration:none;}
</style>
<div id="header-digg">
<a href="http://www.digg.com" target="_blank" class="homeLink">
<em>this is digg.com</em>
</a>
</div>
- 链接伪类实现背景替换
点击查看代码
<style>
#categoryNav li {margin:5px 0;}
#categoryNav li a { display: block; width: 150px;height: 25px;line-height: 25px;color:#F7F2D9;text-decoration: none;background: #04A152 url(/images/html_code_guide/categoryNav.gif) no-repeat left top; text-indent: 10px; }
#categoryNav li a:visited {background-position: right top;}
</style>
<ul id="categoryNav">
<li><a href="#" target="_blank">凤凰博客</a></li>
<li><a href="#" target="_blank">军情观察室</a></li>
<li><a href="#" target="_blank">社会能见度</a></li>
<li><a href="#" target="_blank">时事辩论会</a></li>
<li><a href="#" target="_blank">世纪大讲堂</a></li>
<li><a href="#" target="_blank">王纪言摄影博客</a></li>
<li><a href="#" target="_blank">评论员博客</a></li>
</ul>
分页样式
- Digg.com样式
« 前一页
1
2
3
4
5
6
7
8
9
10
...
2173
2174
后一页 »
点击查看代码
<style>
.pages-digg { font:normal 11px/150% Georgia,'Trebuchet MS', sans-serif;}
.pages-digg a {
display: block;
float: left;
padding: 0.2em 0.5em;
margin-right: 0.1em;
border: #9aafe5 1px solid;
}
.pages-digg a:hover { border-color: #2e6ab1;text-decoration: none;}
.pages-digg a.nextprev {font-weight: bold}
.pages-digg span {
display: block;
float: left;
border: #fff 1px solid;
padding:0.2em 0.5em;
margin-right: 0.1em;
}
.pages-digg span.current { border: #2e6ab1 1px solid; font-weight: bold;
background: #2e6ab1;color: #fff;}
.pages-digg span.nextprev { border: #ddd 1px solid; color: #999; }
</style>
<div class="pages-digg">
<span class="nextprev">« 前一页</span>
<span class="current">1</span>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">7</a>
<a href="#">8</a>
<a href="#">9</a>
<a href="#">10</a>
<span>...</span>
<a href="#">2173</a>
<a href="#">2174</a>
<a href="#" class="nextprev">后一页 »</a>
</div>
- Flickr.com样式
点击查看代码
<style>
.pager-flickr { font-size: 12px; margin-left: auto; margin-right: auto;}
.pager-flickr a {
padding: 4px 6px;
border: solid 1px #9AAFE5;
background: #fff;
text-decoration: none;
margin:0 }
.pager-flickr a:hover {color: #105CB6; border-color: #2E6AB1; text-decoration: none;}
.pager-flickr a.nextprev {
margin-right: 20px;
padding:4px 6px;
border: #9AAFE5 1px solid;
color: #105CB6;
font-weight:bold;}
.pager-flickr span.current {
padding: 5px 6px;
border-color: #2E6AB1;
font-weight: bold;
background: #2E6AB1;
color: #fff;}
.pager-flickr span.nextprev {
margin-left: 20px;
padding: 4px 6px;
border: #ddd 1px solid;
color: #999; }
</style>
<div class="pager-flickr">
<span class="nextprev"><<前一页</span>
<span class="current">1</span>
<a href="#">2</a>
<a href="#">3</a>
<a href="#">4</a>
<a href="#">5</a>
<a href="#">6</a>
<a href="#">7</a>
<a href="#">8</a>
<a href="#">9</a>
<a href="#">10</a>
<a href="#" class="nextprev">后一页>></a>
</div>
2.3 高度自适应的圆角框
天津峰山药王古寺隆重举行琉璃广场奠基洒净法会
4月8日,天津峰山药王古寺隆重举行琉璃广场奠基洒净法会。中国佛教协会副会长、天津市佛教协会会长圣辉法师,中国佛学院教务长向学法师,福建厦门观音寺方丈定恒法师、湖南麓山寺方丈法通法师,闽南佛学院常务副院长界象法师,中国佛学院副教务长广如法师,天津市佛教协会常务副会长智如法师,天津荐福观音寺住持妙贤法师,天津市宗教局、西青区相关领导等嘉宾,和来自各地的四众弟子数千人参加了这一法会。
点击查看代码
<style>
.roundCorner {
background:url(box_middle.jpg) repeat-x bottom left;
width:400px;
}
.roundCorner h1 {
background:url(box_head.jpg) no-repeat top left;
height:20px;
padding-top:10px;
text-align:center;
color:#fff;
font-size:100%;
}
.roundCorner h2 {
background:url(box_foot_small.jpg) no-repeat bottom left;
padding:10px;
text-indent:24px;
color:#333;
font-size:100%;
}
</style>
<div class="roundCorner">
<h1>天津峰山药王古寺隆重举行琉璃广场奠基洒净法会</h1>
<h2>4月8日,天津峰山药王古寺隆重举行琉璃广场奠基洒净法会。中国佛教协会副会长、天津市佛教协会会长圣辉法师,中国佛学院教务长向学法师,福建厦门观音寺方丈定恒法师、湖南麓山寺方丈法通法师,闽南佛学院常务副院长界象法师,中国佛学院副教务长广如法师,天津市佛教协会常务副会长智如法师,天津荐福观音寺住持妙贤法师,天津市宗教局、西青区相关领导等嘉宾,和来自各地的四众弟子数千人参加了这一法会。</h2>
</div>
2.4 导航条
- 水平导航条
点击查看代码
<style>
.navigator { width:100%; height:43px;font-size:12px; font-weight:bold; position:relative; text-align:center;}
.navigator ul,.navigator li{ float:left;}
.navigator ul { position:absolute; top:15px; left:0px;}
.navigator li { background:url(navLineIcon.gif) no-repeat 0 1px; margin-left:10px;}
.navigator li a { height:25px; margin-left:15px; color:#000;}
.navigator li a:hover { color:#333;}
</style>
<div class="navigator">
<ul>
<li><a href="#" target="_blank">生活休闲</a></li>
<li><a href="#" target="_blank">文化视线</a></li>
<li><a href="#" target="_blank">心理测试</a></li>
<li><a href="#" target="_blank">家居家饰</a></li>
<li><a href="#" target="_blank">饮食男女</a></li>
<li><a href="#" target="_blank">科技数码</a></li>
</ul>
</div>
- 垂直导航条(Yahoo.com)
点击查看代码
<style>
.navigator-yahoo {
background:#f8f9fc url(yahoo-menu-bg.gif) repeat-x 0 0;
border:1px solid #BABFC2;
width:150px;
}
.navigator-yahoo li {padding-left:2px;}
.navigator-yahoo li a{
display:block;
width:100px;
height:20px;
padding-left:25px;
padding-top:2px;
background:url(yahoo-menu-icon.gif) 0 0 no-repeat;
font:bold 84% verdana;
}
.navigator-yahoo li a.answers {background-position:-400px -120px}
.navigator-yahoo li a.autos {background-position:-400px -440px}
.navigator-yahoo li a.finance {background-position:0 -761px}
.navigator-yahoo li a.games {background-position:0 -1600px}
.navigator-yahoo li a.groups {background-position:0 -1400px}
</style>
<ul class="navigator-yahoo">
<li><a class="answers" href="#s_2_4_2">Answers</a></li>
<li><a class="autos" href="#s_2_4_2">Autos</a></li>
<li><a class="finance" href="#s_2_4_2">Finance</a></li>
<li><a class="games" href="#s_2_4_2">Games</a></li>
<li><a class="groups" href="#s_2_4_2">Groups</a></li>
</ul>
- 可自适应长度的导航条
点击查看代码
<style>
#navigator-slidingdoor {
float:left;
width:100%;
background:#DAE0D2 url(sliding_door_bg.gif) repeat-x bottom;
font-size:93%;
line-height:normal;
}
#navigator-slidingdoor ul {
margin:0;
padding:10px 10px 0;
list-style:none;
}
#navigator-slidingdoor li {
float:left;
background:url(sliding_door_left.gif) no-repeat left top;
margin:0;
padding:0 0 0 9px;
}
#navigator-slidingdoor a {
display:block;
background:url(sliding_door_right.gif) no-repeat right top;
padding:5px 15px 4px 6px;
text-decoration:none;
font-weight:bold;
color:#765;
}
#navigator-slidingdoor a:hover {
color:#333;
}
#navigator-slidingdoor #current {
background-image:url(sliding_door_left_current.gif);
}
#navigator-slidingdoor #current a {
background-image:url(sliding_door_right_current.gif);
color:#333;
padding-bottom:5px;
}
</style>
<div id="navigator-slidingdoor">
<ul>
<li><a href="#" target="_blank">首页</a></li>
<li id="current"><a href="#" target="_blank">资讯</a></li>
<li><a href="#" target="_blank">时尚</a></li>
<li><a href="#" target="_blank">娱乐</a></li>
<li><a href="#" target="_blank">卫视频道</a></li>
<li><a href="#" target="_blank">时事直通车</a></li>
</ul>
</div>
2.5 图像阴影
- 简单的图像阴影
点击查看代码
<style>
.simpleShadow { background:url(shadow.gif) no-repeat bottom right; float:left;}
.simpleShadow img { margin:-5px 5px 5px -5px;}
</style>
<div class="simpleShadow"><img src="/images/html_code_guide/food.jpg" alt="image shadow" width="200" height="277" /></div>
- 图像阴影
点击查看代码
<style>
.shadow { background:url(shadow.gif) no-repeat bottom right; float:left; position:relative;}
.shadow img { margin:-5px 5px 5px -5px; padding:4px; border:1px solid #a9a9a9; background-color:#fff; display:block;position:relative;}
</style>
<div class="shadow"><img src="/images/html_code_guide/food.jpg" alt="image shadow" width="200" height="277" /></div>
- 不带修饰图片的图像阴影
海鲜食品
点击查看代码
<style>
.imgShadow {float:left; background-color:#9DADC4; margin:5px 5px 15px 3px; position:relative;}
.imgShadow img {padding:3px; background-color:#fff;border:1px solid #c9d6de;border-color:#aec0ce #3d5360 #3d5360 #aec0ce;}
.imgShadow a {background-color:#6B7FA0;}
.imgShadow a,.imgShadow img{display:block; position:relative; top:-1px; left:-1px; }
.imgShadow h5 {display:block; width:150px; position:absolute; bottom:-20px; left:50%; margin-left:-75px; text-align:center;color:#333; font-size:12px;}
</style>
<div class="imgShadow"><a href="#s_2_5_3"><img src="/images/html_code_guide/food.jpg" /></a>
<h5>海鲜食品</h5>
</div>
2.6 表格
- 用于数据显示的表格
各国工业生产能力图表
| 国家\类别 |
钢铁 |
石油 |
煤 |
| 美国 |
非常丰富 |
缺乏 |
很丰富 |
| 哈萨克斯坦 |
很丰富 |
一般丰富 |
相当丰富 |
| 俄罗斯 |
非常丰富 |
很丰富 |
丰富 |
| 中华人民共和国 |
很丰富 |
缺乏 |
异常丰富 |
点击查看代码
<style>
.tableForChart {
font: normal 13px auto "Trebuchet MS", Verdana;
color: #4f6b72;
background: #E6EAE9;
width:98%;
}
.tableForChart caption {
padding: 0 0 5px 0;
font: italic 14px "Trebuchet MS", Verdana;
text-align: right;
}
.tableForChart th {
font: bold 13px "Trebuchet MS", Verdana;
color: #4f6b72;
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
border-top: 1px solid #C1DAD7;
letter-spacing: 2px;
text-transform: uppercase;
text-align: left;
padding: 6px 6px 6px 12px;
background: #CAE8EA url(bg_header.jpg) no-repeat;
}
.tableForChart th.first {
border-left: 1px solid #C1DAD7;
}
.tableForChart th.nobg {
border-top: 0;
border-left: 0;
border-right: 1px solid #C1DAD7;
background: none;
}
.tableForChart td {
border-right: 1px solid #C1DAD7;
border-bottom: 1px solid #C1DAD7;
background: #fff;
font-size:13px;
padding: 6px 6px 6px 12px;
color: #4f6b72;
}
.tableForChart td.alt {
background: #F5FAFA;
color: #797268;
}
.tableForChart th.spec {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #fff url(bullet1.gif) no-repeat;
font: bold 13px "Trebuchet MS", Verdana;
}
.tableForChart th.specalt {
border-left: 1px solid #C1DAD7;
border-top: 0;
background: #f5fafa url(bullet2.gif) no-repeat;
font: bold 13px "Trebuchet MS", Verdana;
color: #797268;
}
/*---------for IE 5.x bug*/
html>body .tableForChart td{ font-size:11px;}
</style>
<table class="tableForChart" cellspacing="0" summary="各国工业生产能力图表">
<caption>各国工业生产能力图表</caption>
<tr>
<th scope="col" class="first">国家\类别</th>
<th scope="col">钢铁</th>
<th scope="col">石油</th>
<th scope="col">煤</th>
</tr>
<tr>
<th scope="row" class="spec">美国</th>
<td>非常丰富</td>
<td>缺乏</td>
<td>很丰富</td>
</tr>
<tr>
<th scope="row" class="specalt">哈萨克斯坦</th>
<td class="alt">很丰富</td>
<td class="alt">一般丰富</td>
<td class="alt">相当丰富</td>
</tr>
<tr>
<th scope="row" class="spec">俄罗斯</th>
<td>非常丰富</td>
<td>很丰富</td>
<td>丰富</td>
</tr>
<tr>
<th scope="row" class="specalt">中华人民共和国</th>
<td class="alt">很丰富</td>
<td class="alt">缺乏</td>
<td class="alt">异常丰富</td>
</tr>
</table>
- 图片列表表格(NYTimes.com)
点击查看代码
<style>
.tableNYtimes {width:98%;table-layout: fixed;}
.tableNYtimes th,.tableNYtimes td { padding:5px;}
.tableNYtimes th { border:1px solid #ccc;border-bottom:0;}
.tableNYtimes th h4 { font-family: Arial, sans-serif;font-size:77%; font-weight:normal; text-transform: uppercase;}
.tableNYtimes th h4 a {color:#000;}
.tableNYtimes td { border:1px solid #ccc;border-top:0; vertical-align:top;}
.tableNYtimes td h5 { font-family:Georgia, "Times New Roman", Times, serif;font-size:92%;font-weight:normal;}
.tableNYtimes td h5 a { color:#004276;}
</style>
<table class="tableNYtimes">
<thead>
<tr>
<th><h4><a href="#">Music »</a></h4></th>
<th><h4><a href="#">World »</a></h4></th>
<th><h4><a href="#">Opinion »</a></h4></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<a href="#"><img src="/images/html_code_guide/nytimes1.jpg" alt="Stevie Wonder and Friends, Here and Gone" width="151" height="151"/></a>
<h5><a href="#">Stevie Wonder and Friends, Here and Gone</a></h5>
</td>
<td>
<a href="#"><img src="/images/html_code_guide/nytimes2.gif" alt="" width="151" height="151"/></a>
<h5><a href="#"></a></h5>
</td>
<td>
<a href="#"><img src="/images/html_code_guide/nytimes3.jpg" alt="Letters: . . .And the Pursuit of Happiness" width="151" height="151"/></a>
<h5><a href="#">Letters: . . .And the Pursuit of Happiness</a></h5>
</td>
</tr>
</tbody>
</table>
- 用于布局的表格(NYTimes.com)
|
|
|
点击查看代码
<style>
.tableNYtimesLayout {width:98%;table-layout: fixed;}
.tableNYtimesLayout td { padding:5px;border:1px solid #ccc; vertical-align:top;}
.tableNYtimesLayout td.ad { width:100px;}
.tableNYtimesLayout td.ad h5 { font-family: Arial, sans-serif;font-size:77%; font-weight:normal; margin:5px 0;}
.tableNYtimesLayout td.ad h5 a { color:#666;}
.tableNYtimesLayout td li { background:url(bullet4x4.gif) no-repeat 0 7px; padding-left:8px;}
.tableNYtimesLayout td li.channel { background:none; margin:5px 0;}
.tableNYtimesLayout td li a {color:#004276;font-size:92%;line-height:150%;font-family:Georgia, "Times New Roman", Times, serif;font-weight:normal;}
.tableNYtimesLayout td li.channel a {color:#000;font-family: Arial, sans-serif;font-size:77%; text-transform: uppercase;}
</style>
<table class="tableNYtimesLayout">
<tbody>
<tr>
<td class="ad">
<a href="#"><img src="/images/html_code_guide/nytimes_trade.gif" alt="ad" width="86" height="40"/></a>
<h5><a href="#">Power E*TRADE: Low Trade Pricing. Get 100 Free Trades--Apply Now! </a></h5>
<a href="#"><img src="/images/html_code_guide/nytimes_store.gif" alt="ad" width="86" height="40"/></a>
<h5><a href="#">Photos, fine art, books and more. </a></h5>
</td>
<td>
<ul>
<li class="channel"><a href="#">World »</a></li>
<li><a href="#">Musharraf Prepares to Drop Army Role</a></li>
<li><a href="#">At Least 35 Dead in Iraq Violence</a></li>
<li><a href="#">Car Bombing Kills 2 in Kabul District Used by Foreigners</a></li>
<li class="channel"><a href="#">U.S. »</a></li>
<li><a href="#">Musharraf Prepares to Drop Army Role </a></li>
<li><a href="#">At Least 35 Dead in Iraq Violence </a></li>
<li><a href="#">Car Bombing Kills 2 in Kabul District Used by Foreigners </a></li>
</ul>
</td>
<td>
<ul>
<li class="channel"><a href="#">Business »</a></li>
<li><a href="#">Home Prices Post Big Drop in Survey </a></li>
<li><a href="#">Postive Data for Abbott’s Proposed Heart Stent </a></li>
<li><a href="#">Google’s Next Frontier: Renewable Energy </a></li>
<li class="channel"><a href="#">Technology »</a></li>
<li><a href="#">NBC Universal to Offer Interactive Ads via TiVo </a></li>
<li><a href="#">Google’s Next Frontier: Renewable Energy </a></li>
<li><a href="#">Bits : Yahoo’s Cyber Monday Meltdown </a></li>
</ul>
</td>
</tr>
</tbody>
</table>
2.7 表单
点击查看代码(使用Table编码)
<style>
.formYahoo table{ font:small/150% Arial, Helvetica, sans-serif; color:#333; width:98%;}
.formYahoo .required { font:0.8em Verdana !important; color:#f68622;}
.formYahoo span.b { font-weight:bold;}
.formYahoo .explain { color:#808080;}
.formYahoo caption {display:none;}
.formYahoo th { font-weight:normal; text-align:right; vertical-align:top; padding:4px; padding-top:8px; width:30%;}
.formYahoo td { text-align:left; padding:4px; width:70%;}
.formYahoo input { width:180px;}
.formYahoo input.submit { width:70px;}
.formYahoo select#content { width:184px; margin:0;}
</style>
<form id="formYahoo" class="formYahoo" action="">
<table summary="使用table来布局的演示">
<caption>
Registration example form
</caption>
<tr>
<th><span class="required">*</span> <label for="fname" accesskey="F">First name:</label></th>
<td><input type="text" id="fname" value="" /></td>
</tr>
<tr>
<th><span class="required">*</span> <label for="lname" accesskey="L">Last name:</label></th>
<td><input type="text" id="lname" value="" /></td>
</tr>
<tr>
<th><span class="required">*</span> <label for="content" accesskey="C">Preferred content:</label></th>
<td>
<select name="content" id="content">
<option value="us" selected="selected">Yahoo! U.S.</option>
<option value="e1">Yahoo! U.S. in Spanish</option>
<option value="b5">Yahoo! U.S. in Chinese</option>
<option value="cn">Yahoo! China</option>
<option value="uk">Yahoo! United Kingdom</option>
<option value="ar">Yahoo! Argentina</option>
<option value="aa">Yahoo! Asia</option>
<option value="au">Yahoo! Australia</option>
<option value="br">Yahoo! Brazil</option>
<option value="ca">Yahoo! Canada in English</option>
<option value="cf">Yahoo! Canada in French</option>
<option value="fr">Yahoo! France</option>
<option value="de">Yahoo! Germany</option>
<option value="hk">Yahoo! Hong Kong</option>
<option value="in">Yahoo! India</option>
<option value="it">Yahoo! Italy</option>
<option value="kr">Yahoo! Korea</option>
<option value="mx">Yahoo! Mexico</option>
<option value="sg">Yahoo! Singapore</option>
<option value="es">Yahoo! Spain</option>
<option value="tw">Yahoo! Taiwan</option>
</select>
</td>
</tr>
<tr>
<th><span class="required">*</span> <label for="sex" accesskey="G">Gender:</label></th>
<td>
<select name="sex" id="sex">
<option value="">[Select] </option>
<option value="m">Male</option>
<option value="f">Female</option>
</select>
</td>
</tr>
<tr>
<th><span class="required">*</span> <label for="yid" accesskey="Y">Yahoo! ID:</label></th>
<td><input type="text" value="" id="yid"> <span class="b">@yahoo.com</span><br />
<span class="explain">ID may consist of a-z, 0-9, underscores, and a single dot (.)</span></td>
</tr>
<tr>
<th><span class="required">*</span> <label for="pw" accesskey="P">Password:</label></th>
<td>
<input type="password" value="" id="pw" /><br />
<span class="explain">Six characters or more; capitalization matters!</span>
</td>
</tr>
<tr>
<th><span class="required">*</span> <label for="pw2" accesskey="R">Re-type password:</label></th>
<td><input type="password" value="" id="pw2"/></td>
</tr>
<tr>
<th></th>
<td><input type="submit" value="Submit" class="submit"/> <input type="reset" value="Reset" class="submit"/></td>
</tr>
</table>
</form>
点击查看代码(使用P和Label编码)
<style type="text/css" media="all">
.formYahoo { font:small/150% Arial, Helvetica, sans-serif; color:#333;}
.formYahoo .required { font:0.8em Verdana !important; color:#f68622;}
.formYahoo .explain { color:#808080;}
.formYahoo .b { font-weight:bold;}
.formYahoo p,.formYahoo div#submit {width: 68%;clear: left; padding:4px; text-align:left;}
.formYahoo label { float: left; width: 35%; padding:4px 4px 0; text-align:right;}
.formYahoo input { width:180px; }
.formYahoo select#sex { margin:0;}
.formYahoo select#content { width:184px; margin:0;}
.formYahoo input.submit { width:70px;}
.formYahoo div#submit { text-align:center;}
</style>
<form id="formYahoo" class="formYahoo" action="">
<p>
<label for="fname" accesskey="F"><span class="required">*</span> First name:</label>
<input type="text" id="fname" value="" />
</p>
<p>
<label for="lname" accesskey="L"><span class="required">*</span> Last name:</label>
<input type="text" id="lname" value="" />
</p>
<p>
<label for="content" accesskey="C"><span class="required">*</span> Preferred content:</label>
<select name="content" id="content">
<option value="us" selected="selected">Yahoo! U.S.</option>
<option value="e1">Yahoo! U.S. in Spanish</option>
<option value="b5">Yahoo! U.S. in Chinese</option>
<option value="cn">Yahoo! China</option>
<option value="uk">Yahoo! United Kingdom</option>
<option value="ar">Yahoo! Argentina</option>
<option value="aa">Yahoo! Asia</option>
<option value="au">Yahoo! Australia</option>
<option value="br">Yahoo! Brazil</option>
<option value="ca">Yahoo! Canada in English</option>
<option value="cf">Yahoo! Canada in French</option>
<option value="fr">Yahoo! France</option>
<option value="de">Yahoo! Germany</option>
<option value="hk">Yahoo! Hong Kong</option>
<option value="in">Yahoo! India</option>
<option value="it">Yahoo! Italy</option>
<option value="kr">Yahoo! Korea</option>
<option value="mx">Yahoo! Mexico</option>
<option value="sg">Yahoo! Singapore</option>
<option value="es">Yahoo! Spain</option>
<option value="tw">Yahoo! Taiwan</option>
</select>
</p>
<p>
<label for="sex" accesskey="G"><span class="required">*</span> Gender:</label>
<select name="sex" id="sex">
<option value="">[Select] </option>
<option value="m">Male</option>
<option value="f">Female</option>
</select>
</p>
<p>
<label for="yid" accesskey="Y"><span class="required">*</span> Yahoo! ID:</label>
<input type="text" value="" id="yid"> <span class="b">@yahoo.com</span><br />
<span class="explain">ID may consist of a-z, 0-9, underscores, and a single dot (.)</span>
</p>
<p>
<label for="pw" accesskey="P"><span class="required">*</span> Password:</label>
<input type="password" value="" id="pw" /><br />
<span class="explain">Six characters or more; capitalization matters!</span>
</p>
<p>
<label for="pw2" accesskey="R"><span class="required">*</span> Re-type password:</label>
<input type="password" value="" id="pw2"/>
</p>
<div id="submit">
<input type="submit" value="Submit" class="submit"/> <input type="reset" value="Reset" class="submit"/>
</div>
</form>
2.8 图文混排
- 浮动的图文混排

Bill Clinton gave a spirited defense of his eight years in office and touted the qualifications of his vice president, Al Gore, who wants to take Clinton’s place in the White House. Get full coverage and read a transcript.
Hundreds of protesters, dressed in black and wearing handkerchiefs over their mouths, clashed with police after a rock concert outside the Democratic Convention.
点击查看代码
<style>
.abcnews-breakingNews,.abcnews-headline { width:415px; font-family:Arial, Helvetica, sans-serif;}
.abcnews-breakingNews img { float:left;}
.abcnews-breakingNews h1,.abcnews-breakingNews h2 {float:left; display:inline;width:200px; margin:0 0 0 10px;}
.abcnews-breakingNews h1 {font-size:136%;}
.abcnews-breakingNews h1 a { text-decoration: underline; line-height:18px;}
.abcnews-breakingNews h2 { font-size:100%;font-weight:normal;}
.abcnews-headline { clear:left;padding-top:10px;}
.abcnews-headline h1,.abcnews-headline h2 { font-size:18px; margin:0;}
.abcnews-headline h1 a { text-decoration: underline;}
.abcnews-headline h2 { font-size:100%; font-weight:normal;}
</style>
<div class="abcnews-breakingNews">
<img src="abcnews.jpg" />
<h1><a href="xczv" target="_blank">Passing the Torch</a></h1>
<h2>Bill Clinton gave a spirited defense of his eight years in office and touted the qualifications of his vice president, Al Gore, who wants to take Clinton’s place in the White House. Get full coverage and read a transcript. </h2>
</div>
<div class="abcnews-headline">
<h1><a href="zv" target="_blank">Cops, Protesters Clash Outside Convention </a></h1>
<h2>Hundreds of protesters, dressed in black and wearing handkerchiefs over their mouths, clashed with police after a rock concert outside the Democratic Convention. </h2>
</div>
- 绝对布局的图文混排
娱乐ENTERTAINMENT
点击查看代码
<style>
.imageText { width:490px; border:1px solid #919191; color:#454545; font-size:92%;}
.imageText a { color:#454545;}
.imageText .head { height:31px; position:relative; border:1px solid #fff; background-color:#aeae8a;}
.imageText .head a { color:#fff;}
.imageText .head h4,.imageText .head ul,.imageText .head li { float:left; color:#fff; }
.imageText .head h4{ font-size:107%;margin-left:10px; margin-top:6px; }
.imageText .head h4 em { font:75% Arial, Helvetica, sans-serif; margin-left:3px; text-transform:uppercase;}
.imageText .head ul { margin-left:20px; margin-top:8px; font-size:100%; font-family:"宋体";}
.imageText .head .more { position:absolute; right:5px; top:11px;}
.imageText .content { position:relative;}
.imageText .content img { margin-top:10px; margin-left:15px; border:5px solid #e1e1e1;}
.imageText .content dl { width:55%; position:absolute; top:10px; right:9px; }
.imageText .content dl dt { font-weight:bold; border-bottom:1px solid #454545; background: url(imageTextIcon.gif) no-repeat 0 0; padding-left:15px;}
.imageText .content dl dt a {color:#3A8ECF}
.imageText .content dl dd { margin-top:10px;}
.imageText .list { position:relative; background-color:#F3F3F3; height:100px; margin-top:5px;}
.imageText .list ul { position:absolute; top:10px; width:47%;}
.imageText .list li { line-height:20px;}
.imageText .list ul.listLeft { left:15px; }
.imageText .list ul.listRight {right:0; border-left:1px solid #919191; padding-left:15px;}
</style>
<div class="imageText">
<div class="head">
<h4>娱乐<em>ENTERTAINMENT</em></h4>
<ul>
<li>[<a href="#" target="_blank">娱闻八卦</a>] </li>
<li>[<a href="#" target="_blank">麻辣大赏</a>] </li>
<li>[<a href="#" target="_blank">影视天地</a>] </li>
</ul>
<a class="more" target="_blank"><img src="/images/html_code_guide/more_eng.gif" /></a>
</div>
<div class="content">
<a href="#" target="_blank"><img src="/images/html_code_guide/imageTextWZX.jpg" /></a>
<dl>
<dt><a href="#" target="_blank">巩俐亮相黄金甲香港首映 回眸一笑不慎露点</a></dt>
<dd><a href="#" target="_blank">前晚劲爆身材表露无遗的巩俐在出席《满城尽带黄金甲》香港首映礼时,不顾寒冷天气,仍以性感Deep V连衣裙上阵,回眸一笑时更不慎露点。</a></dd>
</dl>
</div>
<div class="list">
<ul class="listLeft">
<li>·<a href="#" target="_blank">李家诚徐子淇完婚后神秘失踪</a> </li>
<li>·<a href="#" target="_blank">权相宇对镜自摸令Fans狂叫</a> </li>
<li>·<a href="#" target="_blank">谢霆锋暗示30岁退出娱乐圈</a></li>
<li>·<a href="#" target="_blank">希尔顿将嫁希腊船王后裔布兰妮做伴娘</a></li>
</ul>
<ul class="listRight">
<li>·<a href="#" target="_blank">著名歌手文章18日16:30做客凤凰网</a> </li>
<li>·<a href="#" target="_blank">于娜内衣破裂花容失色</a> </li>
<li>·<a href="#" target="_blank">蔡依林挑战男人极限图</a></li>
<li>·<a href="#" target="_blank">卫兰登台颁奖遇咸猪手 双手护胸</a></li>
</ul>
</div>
</div>