| 发表于:2008-01-09 17:23:027楼 得分:0 |
给你一个我自己写的实际列子我写了注释的 test.htm ———————————————————————————— <!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" lang="gb2312"> <head> <title> 遵循web标准的网页示例 </title> <meta http-equiv="content-type" content="text/html; charset=gb2312" /> <link rel="stylesheet" rev="stylesheet" href="main.css" type="text/css" media="all" /> <link rel="icon" href="/favicon.ico" type="image/x-icon" /> <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" /> <meta content="all" name="robots" /> <meta name="author" content="kefu@zhiweieji.cn,大唐" /> <meta name="copyright" content="www.w3cn.org,自由版权,任意转载" /> <meta name="description" content="网页设计师,web标准,推动web标准在中国的应用" /> <meta content="designing, with, web, standards, xhtml, css, graphic, design, layout, usability, ccessibility, w3c, w3, w3cn, geonado" name="keywords" /> </head> <body> <div id="header"> header </div> <div id="mainbox"> <div id="left"> left </div> <div id="right"> right </div> <div id="content"> <div id="sample"> <a href="http://www.zhiweikeji.cn"> 引用id选择器 </a> </div> <div class="timefont"> 引用类别选择器 </div> </div> </div> <div id="footer"> footer </div> </body> </html> ——————————————————————main.css /* 1.系统默认选择器 */ body { margin: 0px auto; padding: 0px; background: url(../images/bg_logo.gif) #fefefe no-repeat right bottom; font-family: 'lucida grande','lucida sans unicode','宋体','新宋体',arial,verdana,sans-serif; color: #666; font-size:12px; line-height:150%; text-align:center;/*让选择器居中*/ } /*定义链接的颜色 分别是:链接色、已访问过的链接色、鼠标停在上方时链接颜色、点下鼠标时链接颜色 注意,必须按lvha顺序写,否则显示可能和你预想的不一样。记住它们的顺序是"lvha" */ a:link { color: #000; text-decoration: underline; } a:visited { color: #00f; text-decoration: underline; } a:hover { color: #ff3300; text-decoration: underline; } a:active { color: #ff3300; text-decoration: underline; } /* 2.id选择器1 */ /*定义顶部层*/ #header { margin: 0px auto;/*让选择器居中*/ border: 0px; background:#ccd2de; width: 580px; height: 60px; } /*定义中间层 mainbox包含了#left,#rifht和#content */ #mainbox { width: 580px; background: #fff; margin: 0px auto;/*让选择器居中*/ } #left { float: left; margin: 2px 2px 0px 0px; padding: 0px; background: #f2f3f7; width: 170px; } #right { float: right; margin: 2px 0px 2px 0px; padding:0px 0px 0px 0px; width: 200px; background: #ccd2de; } #content { float: right; margin: 1px 0px 2px 0px; padding:0px; width: 200px; background: #e0efde; } /*底部层,clear: both表示本层的左右都没有浮动层*/ #footer { clear: both; margin: 0px auto;/*让选择器居中*/ padding: 5px 0px 5px 0px; background: #ccd2de; height: 40px; width: 580px; } /* id选择器2:sample 1.#sample: 表示层的名称为sample,在页面中用就可以这样来调用: <div id="sample"> </div> 2.margin: 是指层的边框以外留的空白,用于页边距或者与其它层制造一个间距。 "10px 10px 10px 10px"分别代表"上右下左"(顺时针方向)四个边距,如果都一样, 可以缩写成"margin: 10px;"。如果边距为零,要写成"margin: 0px;"。 注意:当值是零时,除了 rgb 颜色值 0%必须跟百分号,其他情况后面可以不跟单位"px"。 margin 是透明元素,不能定义颜色。 3.padding: 是指层的边框到层的内容之间的空白。和 margin 一样,分别指边框的上右下左边到内容 的距离。如果都一样,可以缩写成"padding:0px"。 单独指定左边可以写成"padding-left: 0px;"。padding 是透明元素,不能定义颜色。 4.border: 是指层的边框,"border-right: #ccc 2px solid;" 是定义层的右边框颜色为"#ccc", 宽度为"2px",样式为"solid"直线。如果要虚线样式可以用"dotted"。 5.background: 是定义层的背景。 分2级定义,先定义图片背景,采用"url(../images/bg_logo.gif)"来指定背景图片路径; 其次定义背景色"#fefefe"。"no-repeat"指背景图片不需要重复,如果需要横向重复用 "repeat-x",纵向重复则用"repeat-y",重复铺满整个背景用"repeat"。后面的right bottom 是指背景图片从右下角开始。如果没有背景图片可以只定义背景色 background: #fefefe color用于定义字体颜色。 6.text-align: 用来定义层中的内容排列方式,center 居中,left 居左,right 居右。 7.line-height: 定义行高,150%是指高度为标准高度的 150%,也可以写作:line-height:1.5 或者 line-height:1.5em, 都是一样的意思。 width 是定义层的宽度,可以采用固定值,例如 500px,也可以采用百分比,象这里的"60%"。要注意的是:这个宽度 仅仅指你内容的宽度,不包含 margin,border 和 padding。但在有些浏览器中不是这么定义的,需要你多试试。 */ #sample { margin: 10px 10px 10px 10px; padding:20px 10px 10px 20px; border-top: #ccc 2px solid; border-right: #ccc 2px solid; border-bottom: #ccc 2px solid; border-left: #ccc 2px solid; background: url(images/bg_poem.jpg) #fefefe no-repeat right bottom; color: #666; text-align: left; line-height: 150%; width:60%; } /* 3.类别选择器 <div id="timefont"> </div> */ .timefont { font-size: 10px; color: red; letter-spacing : 0px; } | | |
|