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

4206 3

重点教程一:CSS

[复制链接]
发表于 2006-8-24 03:05:43 | 显示全部楼层 |阅读模式
CSS是Cascading Style Sheets(层叠样式表)的缩写。是一种对web文档添加样式的简单机制,属于表现层的布局语言。' X! l) _% v9 q+ Z5 X. N3 B
) f8 R5 ]; }% ]- j* j0 T9 ^) `2 a
1.基本语法规范
# K1 w' [4 M! A$ X, W! m2 _分析一个典型CSS的语句:
6 Z: ^/ c6 s+ i0 l# m) `5 K
p {COLOR:#FF0000;BACKGROUND:#FFFFFF}

  a2 f% t0 [0 I; v其中"p"我们称为"选择器"(selectors),指明我们要给"p"定义样式;
; D0 E  p$ c* ~/ q样式声明写在一对大括号"{}"中;
# D" ]* E/ z: U* D9 `8 z$ Q, x5 N7 pCOLOR和BACKGROUND称为"属性"(property),不同属性之间用分号";"分隔; 5 T" _% ~4 d* t* J  ?! R% x' m
"#FF0000"和"#FFFFFF"是属性的值(value)。
) j2 r3 j; {0 y. M1 ?2 F% ]& u* d7 _: H5 L
2.颜色值' y0 |& B7 N( r
* ]* ?. `3 m3 }4 U+ W5 l% c
颜色值可以用RGB值写,例如:2 E  W9 c% s7 ?$ s

# C( b. I' _/ p- k: g8 i
color : rgb(255,0,0)
% c3 ]# N- X9 K* r) W$ H
,也可以用十六进制写,就象上面例子
# A! J" [. X9 Y; z& e- E9 I, ^# ~! G; A- I$ D: l' Z3 N- ]# M
color:#FF0000
4 f9 c; c# {6 E: u5 \# _
如果十六进制值是成对重复的可以简写,效果一样。例如:#FF0000可以写成#F00。但如果不重复就不可以简写,例如#FC1A1B必须写满六位。& {6 Y5 Q( e/ H% c$ q6 `5 X
" P' B1 i; y3 J  E' u$ e3 C+ d
3.定义字体
8 [0 X7 g8 ]- y0 T: Fweb标准推荐如下字体定义方法7 m1 `3 v& _6 Q  {4 E% r

) O* R; e8 Y* f- I% j: o  r+ V
body { font-family : "Lucida Grande", Verdana, Lucida, Arial, Helvetica, 宋体,sans-serif; }

" ~: A4 l# w& u1 \- g4 ?" o* C字体按照所列出的顺序选用。如果用户的计算机含有Lucida Grande字体,文档将被指定为Lucida Grande。没有的话,就被指定为Verdana字体,如果也没有Verdana,就指定为Lucida字体,依此类推,;
' Z7 M0 Q/ ~% ~; [Lucida Grande字体适合Mac OS X; 3 a$ a, C2 X# f7 c' P% D- g
Verdana字体适合所有的Windows系统; 5 Q4 y" E0 v% E- u& n( Y+ \/ `8 {! W2 x
Lucida适合UNIX用户   ]6 u, d' J9 t! }3 b: ~6 Y" G
"宋体"适合中文简体用户; - [$ K$ p# \: h/ H0 P7 n+ Y
如果所列出的字体都不能用,则默认的sans-serif字体能保证调用;
6 y+ y  U% H8 f+ f3 d+ P: f- i/ r$ O+ d  Z3 j4 ?
4.群选择器
5 Z$ K: Q- x" S5 {1 b% Q! X9 y7 T' q% H6 G
当几个元素样式属性一样时,可以共同调用一个声明,元素之间用逗号分隔,:/ O/ j+ g: f+ S% E0 }0 D

3 Q3 y7 B3 }6 w. b9 e/ j
p, td, li { font-size : 12px ; }

3 G8 S! L+ d% B6 m# |就是给li下面的子元素strong定义一个斜体不加粗的样式$ T# U7 F; t! m& [9 U4 Z2 }3 a
. b+ U- I% I9 C1 a+ A0 F  I- F% {
6.id选择器
, q: v) P& C% ~* K% y& M; A$ k6 \; c3 g. M# c
用CSS布局主要用层"div"来实现,而div的样式通过"id选择器"来定义。例如我们首先定义一个层" g$ S' w# O+ r, S- O0 t" @+ A
<div id="menubar"></div

  i/ F* L+ t# N* o* r% k
8 e1 w6 P- N& G然后在样式表里这样定义:# L1 c' _- a/ c: m

! _5 W! G% u& p2 r* W
# l% f" c1 O( O6 H8 |( Y
#menubar {MARGIN: 0px;BACKGROUND: #FEFEFE;COLOR: #666;}
6 L7 d' H/ r& L) a4 f% Q2 x1 P
其中"menubar"是你自己定义的id名称。注意在前面加"#"号。! I' d3 c* I/ `9 s0 D$ P

) M9 Q- q7 k6 W+ f; `$ ], Oid选择器也同样支持派生,例如:% m/ s8 G, r. v" C
#menubar p { text-align : right; margin-top : 10px; }
! K* Z- c* {; m
这个方法主要用来定义层和那些比较复杂,有多个派生的元素。' C: n* Y! t, D, D

+ D1 n1 U& `1 B6 V7 _, ^6.类别选择器( L; g) c- ]$ h! e0 ]

4 v6 H/ |3 S% u& j2 D6 k在CSS里用一个点开头表示类别选择器定义,例如:
" S; m" T* A" r5 L
.14px {color : #f60 ;font-size:14px ;}

' N$ Q' G8 q7 w9 P/ a2 e0 [% `2 p; y2 a
/ E+ t1 L% ]( U( z6 _在页面中,用class="类别名"的方法调用:
/ a8 m9 q0 R0 F9 x
<span class="14px">14px大小的字体</span>
0 ?& R) h' E9 A1 }. S' U; L: P

0 L' D1 |3 m! U3 j/ c" |* A" i这个方法比较简单灵活,可以随时根据页面需要新建和删除。
, p6 H) y8 f7 s5 T0 T9 ~% D5 x5 D  V" s! }) v
7.定义链接的样式
% h* d, A0 N2 B7 _4 m. PCSS中用四个伪类来定义链接的样式,分别是:a:link、a:visited、a:hover和a : active,例如:4 @7 W; l7 {5 a" ~1 V& s+ Y
a:link{font-weight : bold ;text-decoration : none ;color : #c00 ;}
, c) c3 l, }# I2 E& n, Oa:visited {font-weight : bold ;text-decoration : none ;color : #c30 ;}$ [  V0 i6 N3 P& |9 Z! W$ r6 l
a:hover {font-weight : bold ;text-decoration : underline ;color : #f60 ;}
" ]) R6 {$ |* M* ?' za:active {font-weight : bold ;text-decoration : none ;color : #90 ;}

* @3 `8 h( W- c* p: c& @: O5 h! U& I# Y  l
以上语句分别定义了"链接、已访问过的链接、鼠标停在上方时、点下鼠标时"的样式。注意,必须按以上顺序写,否则显示可能和你预想的不一样。记住它们的顺序是“LVHA”。
发表于 2006-8-24 03:07:58 | 显示全部楼层
html语法和css都是一门必修的功课,先一点一点的跟大家解释,然后大家可以找这方面的资料看看,到时候我再以我们自己站的实例让大家分析
发表于 2006-8-24 03:09:21 | 显示全部楼层
<style type="text/css"><!--
) J# I. n4 I0 ~a                        { text-decoration: none; color: {LINK} }
% W  f% S/ T: R" D5 F( X3 qa:hover                        { text-decoration: underline }3 a4 n9 V/ ~$ u6 \0 h
body                        { scrollbar-base-color: {ALTBG1}; scrollbar-arrow-color: {BORDERCOLOR}; font-size: {FONTSIZE}; {BGCODE} }4 ?# Z; M0 }) b  V" I$ a3 P
table                        { font: {FONTSIZE} {FONT}; color: {TABLETEXT} }2 @# J& f( K2 D; |% d
input,select,textarea        { font: {SMFONTSIZE} {FONT}; color: {TABLETEXT}; font-weight: normal; background-color: {ALTBG1} }. g+ G) c! c- x" z' D" o; ~1 \
form                        { margin: 0; padding: 0}$ W+ ~: [" }& l, ~# W. W
select                        { font: {SMFONTSIZE} {SMFONT}; color: {TABLETEXT}; font-weight: normal; background-color: {ALTBG1} }" P/ y/ X4 K# M2 B
.nav                        { font: {FONTSIZE} {FONT}; color: {TEXT}; font-weight: {BOLD} }2 G+ _% i; H% b; J8 ?  k
.nav a                        { color: {TEXT} }" i+ R$ ^) ~* i- V# S
.header                        { font: {SMFONTSIZE} {FONT}; color: {HEADERTEXT}; font-weight: {BOLD}; {HEADERBGCODE} }
* t5 E$ P6 y* l# I6 i.header a                { color: {HEADERTEXT} }% z9 z' K3 d3 D! `6 k3 K( U  [
.category                { font: {SMFONTSIZE} {SMFONT}; color: {CATTEXT}; {CATBGCODE} }
& h2 b7 K: X! ^.tableborder                { background: {INNERBORDERCOLOR}; border: {BORDERWIDTH}px solid {BORDERCOLOR} }
) J0 y- [  P8 m: Q4 y( L' c.singleborder                { font-size: 0px; line-height: {BORDERWIDTH}px; padding: 0px; background-color: {ALTBG1} }" J9 {! b; I" G# a
.smalltxt                { font: {SMFONTSIZE} {SMFONT} }
& \: w' o2 s! w) \. n.outertxt                { font: {FONTSIZE} {FONT}; color: {TEXT} }
; _$ t: v1 l6 l3 b8 w+ U.outertxt a                { color: {TEXT} }
% L* ?1 y+ c% b; A.bold                        { font-weight: {BOLD} }/ k2 z- N' ?* |) |3 ?/ s
.altbg1                        { background: {ALTBG1} }$ |. L. j& B& \+ X# m7 N# r' _
.altbg2                        { background: {ALTBG2} }
+ V2 j8 L: J5 \7 v1 C+ H.maintable                { width: {MAINTABLEWIDTH}; background-color: {MAINTABLECOLOR} }
) Z- H* G3 B. G& h.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}
" L% x( P: m" U+ i  T3 G.popupmenu_option { font: {SMFONTSIZE} {SMFONT}; color: {CATTEXT}; WHITE-SPACE: nowrap; background: {ALTBG1} }
# T* d/ I7 t! G.popupmenu_option A {COLOR: {CATTEXT}; TEXT-DECORATION: none}
+ R/ K7 @* U. ?/ `! b+ A.popupmenu_option A:hover {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}6 r5 u. o! j: Y+ @
.popupmenu_option A:active {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}8 h, P% X& d) Z: p; l. l
.popupmenu_highlight {FONT: 12px Tahoma, Verdana; CURSOR: pointer; font-weight: normal; color: {HEADERTEXT}; WHITE-SPACE: nowrap; {HEADERBGCODE} }
! F# d  D8 @3 ?' c6 A+ M.popupmenu_highlight A:link {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}3 |: o+ K0 t! e9 \9 ?% _" @
.popupmenu_highlight A:visited {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}0 [+ w6 x4 N8 l
.popupmenu_highlight A:hover {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}  v, |8 ?4 a( Q
.popupmenu_highlight A:active {font-weight: normal; color: {HEADERTEXT}; TEXT-DECORATION: none}
7 U5 w, M0 f# H4 c4 i4 z. |8 k
; N4 T. ]$ j/ N- a' J--></style>

7 ]! ?0 @( M. d4 s
- [* v( |0 Y2 C, f3 _上面这段就是我们论坛的CSS内容,大家分析下看看,都是什么意思??
发表于 2007-3-26 11:35:33 | 显示全部楼层
日!!脑袋要炸了!!
您需要登录后才可以回帖 登录 | 注册

本版积分规则

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

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

GMT+8, 2026-6-10 02:24 , Processed in 0.080766 second(s), 6 queries , Redis On.

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

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