技术部 收藏本版 今日: 0 主题: 115

4930 3

重点教程一:CSS

[复制链接]
发表于 2006-8-24 03:05:43 | 显示全部楼层 |阅读模式
CSS是Cascading Style Sheets(层叠样式表)的缩写。是一种对web文档添加样式的简单机制,属于表现层的布局语言。
9 S- K" r: i; R* H4 T! U: F
" h0 V+ w7 H! Q  p( w* D8 d+ |1.基本语法规范
8 |& F2 a% O. k0 |8 z0 B# ?分析一个典型CSS的语句:
6 Z6 C  @) a9 N! g! T# v
p {COLOR:#FF0000;BACKGROUND:#FFFFFF}

) i' g3 V0 a& L其中"p"我们称为"选择器"(selectors),指明我们要给"p"定义样式;
8 `( _7 m' e( t- g样式声明写在一对大括号"{}"中; ; s9 E+ ?% G) }3 L2 O' i, d  _) F0 J
COLOR和BACKGROUND称为"属性"(property),不同属性之间用分号";"分隔; 1 W8 C( e0 w8 s+ _8 n. y
"#FF0000"和"#FFFFFF"是属性的值(value)。
- K4 ~; d2 S4 d6 f6 d
: }8 M" z$ K9 A: e+ H2.颜色值
5 ^& M1 g5 H4 D% y3 `, ]: |+ L( v4 y4 i/ O3 l% |
颜色值可以用RGB值写,例如:
3 P* X  w! V, [% G) d' V" ]0 l( j1 o7 o9 d5 _" p' t
color : rgb(255,0,0)

, C- Q# v( B- U5 m& U9 O,也可以用十六进制写,就象上面例子7 D5 s- M5 f7 j7 d( W2 p- O" t

: z3 ~! w& G2 q+ c' G
color:#FF0000
6 V# J) H& D& K. W
如果十六进制值是成对重复的可以简写,效果一样。例如:#FF0000可以写成#F00。但如果不重复就不可以简写,例如#FC1A1B必须写满六位。
& x3 y" A* y6 q$ X+ ^% e: P- V0 y/ _) ~5 U' @
3.定义字体
: Q5 |) P0 `1 _. |4 B5 b% N: aweb标准推荐如下字体定义方法8 Q9 g4 H* P. f( ~! q# p# P

5 N  P8 M5 L. _  f5 Z/ f# \
body { font-family : "Lucida Grande", Verdana, Lucida, Arial, Helvetica, 宋体,sans-serif; }

% R8 }# k! `6 w0 T; F字体按照所列出的顺序选用。如果用户的计算机含有Lucida Grande字体,文档将被指定为Lucida Grande。没有的话,就被指定为Verdana字体,如果也没有Verdana,就指定为Lucida字体,依此类推,; ! H& {" J4 J) D  G# E+ a
Lucida Grande字体适合Mac OS X;
- _( i( Q& {! ^2 V2 _% i, BVerdana字体适合所有的Windows系统;
8 R; o4 m. [( T" JLucida适合UNIX用户
3 p& j; K* N/ J"宋体"适合中文简体用户;
( j9 n- g, i2 A/ @. Y9 Q如果所列出的字体都不能用,则默认的sans-serif字体能保证调用;: p" y3 m, v5 E: n( F' b$ d, V( U% R

! h3 U; ]4 f+ x% u/ T0 V4.群选择器# d, c! N1 l, Q

: O8 _  S$ ], P当几个元素样式属性一样时,可以共同调用一个声明,元素之间用逗号分隔,:
+ e* O( C9 C9 q+ ]* l
0 o: H5 V  _+ \4 a* q
p, td, li { font-size : 12px ; }

4 z$ n& M& n2 Z: Y7 a( Q. F. ~就是给li下面的子元素strong定义一个斜体不加粗的样式
& K0 \- o" ]  w$ `2 @5 C, X2 @: f* a* m% s6 {; C
6.id选择器
1 L" f8 T# S! t! D3 d& p4 `
/ a0 s! b# z3 ^. ?2 [; w用CSS布局主要用层"div"来实现,而div的样式通过"id选择器"来定义。例如我们首先定义一个层
0 e3 t$ z# p3 Z* c4 I. n* @
<div id="menubar"></div

& m# i" L, i  k( F! K, G! y( P) K- k8 n# U- L( i3 T6 ^) Y
然后在样式表里这样定义:$ H7 ~' x# Q& p( v, ]* ]: |8 A  |
7 Z6 H: A) J6 ?9 K
, J6 L8 w+ S$ E. U4 X" v, v
#menubar {MARGIN: 0px;BACKGROUND: #FEFEFE;COLOR: #666;}

- x# {$ g/ P7 a& `其中"menubar"是你自己定义的id名称。注意在前面加"#"号。
1 j/ Z" I+ y% t4 |) w) B9 W" G, r9 f/ t: \6 Q1 `+ k
id选择器也同样支持派生,例如:4 n3 B5 \& Q3 N: _5 A( y
#menubar p { text-align : right; margin-top : 10px; }

) A- n7 V% ]4 [1 i9 t  ^这个方法主要用来定义层和那些比较复杂,有多个派生的元素。5 q. {7 ]' m- f' H- m1 r; c
! X) U4 n- E- m7 w2 a
6.类别选择器
* m3 o6 O+ d( v4 c, l8 j# t/ E: g9 V* Y( x( r
在CSS里用一个点开头表示类别选择器定义,例如:7 v0 h5 P+ U& `% d8 m1 S
.14px {color : #f60 ;font-size:14px ;}
2 n1 I$ F, q  O5 n
, Z- ^- ]4 l( m1 e) P7 g" c7 a0 }
在页面中,用class="类别名"的方法调用:) V) h7 t4 k! ~- f$ U0 f5 v
<span class="14px">14px大小的字体</span>
' s( C! ]7 D6 S: W4 N

/ ?0 b0 i( ~8 D  G这个方法比较简单灵活,可以随时根据页面需要新建和删除。
4 q9 ~' t. `! |8 k' o- l1 U" P( o: K# S3 f4 X! @$ z! e
7.定义链接的样式
- L- ?+ L+ ~( l0 tCSS中用四个伪类来定义链接的样式,分别是:a:link、a:visited、a:hover和a : active,例如:$ V3 @5 {- K/ N0 a
a:link{font-weight : bold ;text-decoration : none ;color : #c00 ;}
4 c# ]/ P# v7 ?# n( y8 Wa:visited {font-weight : bold ;text-decoration : none ;color : #c30 ;}
+ ~/ `$ q9 G7 b! c" Oa:hover {font-weight : bold ;text-decoration : underline ;color : #f60 ;}$ y0 z3 k6 M* |6 K5 G# P! m
a:active {font-weight : bold ;text-decoration : none ;color : #90 ;}

9 H3 e1 E. H; n' l& o$ C) P! A% h) U4 d' a
以上语句分别定义了"链接、已访问过的链接、鼠标停在上方时、点下鼠标时"的样式。注意,必须按以上顺序写,否则显示可能和你预想的不一样。记住它们的顺序是“LVHA”。
发表于 2006-8-24 03:07:58 | 显示全部楼层
html语法和css都是一门必修的功课,先一点一点的跟大家解释,然后大家可以找这方面的资料看看,到时候我再以我们自己站的实例让大家分析
发表于 2006-8-24 03:09:21 | 显示全部楼层
<style type="text/css"><!--1 u& d) `  s/ o) _9 W
a                        { text-decoration: none; color: {LINK} }
% u5 K* \7 S) H  s# ma:hover                        { text-decoration: underline }
$ a* G% L8 D. E" e. |body                        { scrollbar-base-color: {ALTBG1}; scrollbar-arrow-color: {BORDERCOLOR}; font-size: {FONTSIZE}; {BGCODE} }+ H& c! ^+ f- c: C/ `; N7 B& D9 q
table                        { font: {FONTSIZE} {FONT}; color: {TABLETEXT} }  ^5 \6 f" n; S6 x2 |4 Y; p# K
input,select,textarea        { font: {SMFONTSIZE} {FONT}; color: {TABLETEXT}; font-weight: normal; background-color: {ALTBG1} }
" m, M, t* X% j( Zform                        { margin: 0; padding: 0}$ Z% O% P" C7 F7 g" d
select                        { font: {SMFONTSIZE} {SMFONT}; color: {TABLETEXT}; font-weight: normal; background-color: {ALTBG1} }, Z6 Y& q( u6 x. G) i
.nav                        { font: {FONTSIZE} {FONT}; color: {TEXT}; font-weight: {BOLD} }
; g4 `  H) \) u  F4 F.nav a                        { color: {TEXT} }9 V) ?  x( p" w0 O# a
.header                        { font: {SMFONTSIZE} {FONT}; color: {HEADERTEXT}; font-weight: {BOLD}; {HEADERBGCODE} }! {4 c1 Y2 E% a
.header a                { color: {HEADERTEXT} }2 _0 x" ^/ [7 _2 E( a
.category                { font: {SMFONTSIZE} {SMFONT}; color: {CATTEXT}; {CATBGCODE} }9 e6 \: D  g+ `! h6 ?1 Y5 F0 R
.tableborder                { background: {INNERBORDERCOLOR}; border: {BORDERWIDTH}px solid {BORDERCOLOR} } % Z7 ^' e9 b7 [+ {" C* }5 q
.singleborder                { font-size: 0px; line-height: {BORDERWIDTH}px; padding: 0px; background-color: {ALTBG1} }
% m! |" r# q' x.smalltxt                { font: {SMFONTSIZE} {SMFONT} }
$ R1 I2 K- l; y3 q4 |' m, Z7 o.outertxt                { font: {FONTSIZE} {FONT}; color: {TEXT} }
# {! p- x% I0 b  c9 q, ^( ^4 N* w' Q.outertxt a                { color: {TEXT} }+ S  i& o' T, I' `
.bold                        { font-weight: {BOLD} }
6 \' \. R9 m- t- n7 J. j2 F6 s.altbg1                        { background: {ALTBG1} }
* A* B, l0 T( L' D& u.altbg2                        { background: {ALTBG2} }
" ~- e* e0 X# _$ u; B.maintable                { width: {MAINTABLEWIDTH}; background-color: {MAINTABLECOLOR} }
7 ^/ q6 D1 v" p1 M/ j.popupmenu_popup {BORDER-RIGHT: {BORDERCOLOR} 1px solid; BORDER-TOP: {BORDERCOLOR} 1px solid; BACKGROUND: #ffffff; BORDER-LEFT: {BORDERCOLOR} 1px solid; COLOR: {CATTEXT}; BORDER-BOTTOM: {BORDERCOLOR} 1px solid}
' _4 q" p1 t4 [5 N, w# Q7 w& m8 V.popupmenu_option { font: {SMFONTSIZE} {SMFONT}; color: {CATTEXT}; WHITE-SPACE: nowrap; background: {ALTBG1} } 6 c' o' Q% n9 U0 x8 g% X
.popupmenu_option A {COLOR: {CATTEXT}; TEXT-DECORATION: none}
5 K7 D8 |  G, S, l/ t9 W.popupmenu_option A:hover {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}
2 @/ {5 Z- c2 x% Z8 z.popupmenu_option A:active {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}# r* V0 J$ b- e* h
.popupmenu_highlight {FONT: 12px Tahoma, Verdana; CURSOR: pointer; font-weight: normal; color: {HEADERTEXT}; WHITE-SPACE: nowrap; {HEADERBGCODE} }9 o" Q& ?! j* M5 Y0 p% q
.popupmenu_highlight A:link {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}
6 {# R  \$ w! Q3 ?.popupmenu_highlight A:visited {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}& J' w- a7 @+ K/ I
.popupmenu_highlight A:hover {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}* \. f5 x& _2 t
.popupmenu_highlight A:active {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}
; I" R. u- J: \- l
0 M% V! e8 I& {0 r/ U--></style>

9 u7 \" W9 y2 \4 s
8 L* A- e* o, k& Y5 B  b上面这段就是我们论坛的CSS内容,大家分析下看看,都是什么意思??
发表于 2007-3-26 11:35:33 | 显示全部楼层
日!!脑袋要炸了!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

傲天阁游戏公会
联系我们
咨询电话 : 020-88888888
事务 QQ : 85075421
电子邮箱 : admin@admin.com

小黑屋|手机版|Archiver|傲天阁游戏公会 ( 粤ICP备14058347号 )|免责声明

GMT+8, 2026-10-7 21:12 , Processed in 0.096446 second(s), 7 queries , Redis On.

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表