典型的三行二列居中高度自适应布局 MZn7gT0
qoB
'}P)iS2
67 7p9{:
-------------------------------------------------------------------------------- ,{%/$7)
yeE_1C .
&^63*x;hE
这个页面在mozilla、opera和IE浏览器中均可以实现居中和高度自适应。我们来分析代码:
0>H<6Ja
d+fmVM?p
完整代码 QMy;?,
6:-qL}
<html> '3[Ecy#
.{5)$w>
Ea!}r|~]0
z+PSx'#}
<head> z ]o&^Q
K?-K<3]9f
;)0vxcMB
X2dTV}~i
<style type="text/css"> 7R7g$
=ub&@~E
73Mh65
%dw-}1X
body{ .N_0rPO,Kw
^._)HM
B(Y{
^=OjsN
background:#999; F mh;d*IT
|WXu;uf$.u
H!Uy4L~>
-T4?5T_
text-align:center; a=p3oh?%-O
(G#)[0<fX
e<~uU9
lg1
HY5g>wv@
color: #333; Y&Pi`E9=
(W=z0Lqu
%?X~,
1kb?y4xeJ
font-family:arial,verdana,sans-serif; Z=825[p
!uO|1b
5{,/m"-
/Wg$.<!5}
} H&mw!=FV0
B964#4&
9
xzW]D0o0
T>vH ZZiO
#header{ }k \a~<'X
Pk~P
{(ey!O
\w^U<_zq
width:776px; hJhdHy=U
NkNw9?:#4
9g^@dfBV
#`y7L4V*o
margin-right: auto; (d4zNYK
B`"-~4YAf
&IXr*I
z[ z'.{;D
margin-left: auto; ^4B6IF*
j#-ZL-N
D~NH 4B
FT `y3~
padding: 0px; +r4US or
[rqq*_eB
(zk'i13#6
<wj2:Z0
background: #EEE; d/Zt}{
Rp}6}4=d
s)
V7$D
Qs#v/r
height:60px; =!{}:An1$
?#pL\1"E
'e;*V$+
$'?CY)h{
text-align:left; P)>WIQSr
t!D=oBCro
j(/"}d3osm
?o9l{4~g
} #contain{ .Zf#L'Rf
W
86S)+h
.?!{. D
$AG.<
margin-right: auto; Ujq)h:`
<C#
s0UX
(:Bo'q
S
3w!oJB
margin-left: auto; kJJQcjAP:
r-4I{GPb
(t<i?>p
(Clf]\_II
width: 776px; ~NU~jmT2
ax>en]rNP
>[ lj8n
,_\h)R_
} #mainbg{ Dih~5
`1M_rG1/+
3,N7Nfe
V&h,v%$
width:776px; Axj<e!{D
C[gSiL
5>h2WL
'["Y;/>
padding: 0px; 5'+g'9
Oo rH
>a_K:O|AJ
yMX4 f
background: #60A179; -cY/M~
FY#`]124*
F^A1'J
(:-DuUt
float: left; "]zq<LmX
,,fLK1
P5] cEZ n
\f /<#'
} r'xa'6&
[}P|OCW
kE6\G}zj
BtU,1`El5
#right{ u"C`S<c
= 2My-%i
r10)1`[
G@,qO#5&
float: right; pjjs'A*y
rp(`V@x3
Ge(r6"%7
.JQR5R |Q
margin: 2px 0px 2px 0px; MzJ5_}
2uiiTg>
}"q1B
%pTbJaM\U
padding:0px; 5
0~L(<
Hej0l^
6@Eip[e
Dk]Y\:
width: 574px; (Ca\$p7/
3@6f%Dyj
g*Cs/w
Jc{zi^)(EN
background: #ccd2de; $R7d*\(G
Q?[k>fu0
ckhW?T>l
.>CqZN,^
text-align:left; U%w-/!p
K})j5CJ/
3y 0`G8P'h
-R6z/P(}
} CHBCi) '6h
*pI3"_
H+*o @0C\~
v]_{oj_(-
#left{ puMpUY
3ck;~Ncj<
9O}YtX2
F Fg0}
float: left; HC!$Z`}Y
= @ph
oleRQ=
Q@]#fW\Y
margin: 2px 2px 0px 0px; +TUtVG
C7q bofoV
&a48DCZ
6PJ0iten
padding: 0px; u!{P{C
ZH&%D*a&
fyQAQZT
6Y}#vZ
background: #F2F3F7; NSM-p.I9
$:mCyP<y
:Q&8DC#]
p|AIz3
width: 200px; j##IJm
sfVtYIu
b/O~f8t
vK2L"e
text-align:left; S=M$g#X`5
,)oUdwR k
jsi\*5=9p<
Pf@8C{I
} npbNUKdz
qIO)Z
OZk(VMuI
\[Rh\v&
#footer{ EJZl'CR
,v)@&1Wh:
tr/S*0$
+J+]P\:
clear:both; m=j7 vb
})T_D\2M
bU_9GGG|
X "1q$xwc
width:776px; Xg.\B1d
8 +uOYNXsA
hQl3F6-ud
9\Yj`,i5
margin-right: auto; 6,s@>8n
2r[Q$GPM<
dos$d3B4
,bJZs-P0
margin-left: auto; 9e8@0?0
Isoqs(Oi
F/@#yQv?
dsJ}C|N
padding: 0px; 7{<t]wQq
p~=%CG^5
$K;4=zN>t:
bQ
background: #EEE; _!w# {5~
4*m\Zoq>
p?8>9
Zf(ucAhL
height:60px;} Ig5J_Z^]b
D~2,0K
vxbO>c
d![EnkyL;
.text{margin:0px;padding:20px;} ScM2_k`D
p3sz32RX
OEZXV ;F
<8jn_6
</style> y .
AN0
-41L^Di\
r1F5&?{q
1v,4[;{
</head> $,'r}
%
c5O1h8
uQpV1o5iA
R,6?1Z:J
<body> js k<N
J,P7k$t2vv
gsT%_2>CL
6=|Q>[K
<div id="header">header</div> _K/h/!\n
!cWKY\lpv
_3kAN.g
I /> .P
<div id="contain"> ))306*X\
|%b' L.$4
N2q'$o
{e>}.R
<div id="mainbg"> P]!eM(
C]eb=rw$
X*d,z~k%*d
Lo9+#ITyx
<div id="right"> 5TzMv3;in2
RHE< QG
~~wz05oRG
?vM{9!M
<div ,X9Y/S
l
W 4 )^8/
0 ,Bd,<3
qItj`F)d
class="text">right<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p></div> 8G(wYlxi
`[CXxp
oh,Nu_!
//|9J(B]
</div> 'B6D&xn'%&
wK|&[ms
5RZAs63t
@I_A(cr
<div id="left"> 2nOQ48haT
4sROMk=l
5?6ATP:[
/:C"n|P7Z
<div class="text">left</div> }2JSa8
h:j-Xd$H+
MqXA8D
"f5u2=7 }
</div> fZXd<Fg+
(3=. 3[
p2w/jJMD
!4-NbtT
</div> /C3=-Hp
21w<8:Vg
,!bOzth2>K
?Tb'J`MO
</div> IKAF%0[R|j
Q7`zrCh
`^|mNh
scN}eg:5
<div id="footer">footer</div> &X +@,!
24|:VxO
ZtDHNL
{s_0[>
</body> X9zTz2 Fy
)e]:T4*vo
WMl_$Fd6
o<T>G{XYB
</html> 7.akp
QAcvv 0Hv
/`2VJw
6U# C
vWzNsWPK"{
~5]AXi'e~
<head> b@5&<V;r2
uodO^5"-
[y>Q3UqN
cCWOGd
<style type="text/css"> I]ywO4
]:]2f9y
Z p]Bs
vad" N
body{ !YAkHrF`[0
OM2|c}]ZQ
c3oI\lU
EL~s90C
background:#999; ^!Bpev
KAEf4/
'KyT]OObS
&tp5y}=n
text-align:center; $0cMrf@
LhV4 ^\+
-cIc&5CS
(;Lz`r'
color: #333; L{
.r8wSrI
g/VC$I!'
HQ2in_'
MS,H12h
font-family:arial,verdana,sans-serif; B(b[Dbb
1mA)=hu
o{>hOs
&
/?2yo{Fg
} 9DPf2`*$
X(Ef=:
zA( 2+e 7
dbnH#0i
#header{ Q"Q|]f*
?V*>4A
I+u=H2][2
^_2Ki
width:776px; ?e&CbVc4
S2j7(T;~YB
X,T^(p
AO^F6Y/
margin-right: auto; :~6%nFo
7W}~c/ %
,0#OA*0B
@JN%P}4)
margin-left: auto; vs6`oW"{#
HjnHl-
!j7b7<wR
YXD1B`23
padding: 0px; !gJAK<]iW
W,w g@2
Wy4v~]xd%
:5@7z9 >
background: #EEE; E*RP8
;Oe6SNquT
%NxNZe
wl(}F^:/`
height:60px; Z/Mp=273
bh+R9~
E 8,53$
FVF:1DT
text-align:left; lzm9ClkfH
QRt(?96
O7rm(
*?\2Ohp
} #contain{ /vU9eh"%
Do2y7,jv
iW |]-Ba\
.l#Pmd!
margin-right: auto; rEddX
5|H?L@_9
Rzb663d
eb( =V*
margin-left: auto; guFR5>-L
=E
|[8 U)
CR,
Y%0vQ
BB>7%~3f
width: 776px; _Zb_9&
&dOV0y_
X}p4yR7'
@?gH3Y_
} #mainbg{ xES+m/?KlZ
%f:'A%'Qb
hpAIIgn
-,XS2[
width:776px; fnB-?8K<
EE%OD~u&9#
aIqNNR
*NXwllrci
padding: 0px; }Pw5*duq
5i1 >z{
[a+?z6qI\}
+S3'ms
background: #60A179; *wh'4i}u
nq6]?ZJ
"rAm6b-`
MTLcLmdO
float: left; :ye)%UU"|:
J^t=.-a|
MfYe @;m
n,AN&BZ
} 75^-93
6j`
waK
A= ,q&
;$|+H"g|
#right{ ytAhhwN~
kdWi!Hp
w#JF7;
9Ft)VX
float: right; *riGi
T /]ayc:
`
0\hm`
mTs[3opg
margin: 2px 0px 2px 0px; ShSh/0
O+'Pq,hn
71)HxC[6vA
"bw4{pa+
padding:0px; 071wo7
"%}PVO!
k+s<;{
f$H"|Mbe
width: 574px; ("{AY?{{
_L:
/2
u 6%56 %^f
wI`uAZ="
background: #ccd2de; Ebq5P$
}4bwLO
_ROe!w 1
R'9TD=qEK
text-align:left; #z5'5|3
9Y/c<gbY
f'#7i@Je
{8UBxFIM(
} SS H/q/
UO!OO&l!
<:%Iq13D
%K%8
~B
#left{ \kg2pF[V
pf2$%lE
63k8j[$
vn
kktD'n
float: left; ?j $z[_K
sN;U,{
'x!q*|zF2
Q)Ppx 7)
margin: 2px 2px 0px 0px; +J#H9>To!
52:oe1-8
3g5i5 G\
g/Qr]:;
padding: 0px; ;w@:
^ S%4R'
/,B"H@J
bu$5gGWVf
background: #F2F3F7; k:d'aP3
v3hNvcMpf
-
+>~
fEgZ/p!g
width: 200px; 1`h`-dqr#
57HMWlg
@NV$!FB<
#"f:m`
text-align:left; %3kqBH!d
^ ]`<nO
X?1 :Z|pJ
Q.cxen
} .11iulQ
>~ne(n4qy
1{u;-pg
r_R|.fl<[
#footer{ dnN"
VF6@;5p
R;,&CQUl
OBj.-jL
clear:both; wRLkO/Fw
> m5j.GP;
GR|Vwxs<@P
B4J^ rzK
width:776px; ty7a&>G
-;Hd_ ~O>j
G\Sd!'?p
iv56zsR
margin-right: auto; ;2bG-v'4vO
U);
,Opr
fHwh6|
C#vh2'
margin-left: auto; Y`c\{&M6
%P yU3
C~6aX/:
hbN*_[
padding: 0px; ~A"ODLgU9
(/FPGYu3h
ko ~iDT
La3f{;|u5M
background: #EEE; /V3*[
r^Gl~sX
E9
q8tE}
Te5_T&1Z
height:60px;} PhW#=S
)u[2TI1
&_!BMzp4
,`H=%#
.text{margin:0px;padding:20px;} )zr/9aV
( 6r9y3'
/>+JK5
Z.,Pl
</style> ^hZwm8G
"I_3!Yu
vA+ RZ
nA+[[(6
</head> f~"3#MaV
A$|> Jt
`[Lap=.'.
rro,AS}
<body> 6G1Z"9<2*
YS~\Gls%
+F 5 Dc
0MPsF{Xw[
<div id="header">header</div> eW\_9E)cY
O|av(F9
5t0i/&zX
Gb~q:&IUr
<div id="contain"> -?@$`{-K
>%d]"]
l<v/T
[i&z_e)
<div id="mainbg"> ~ocd4,d=
hWDgMmo7
8l)l9;4 6
J"[OH,/_
<div id="right"> hRA.u'M
B&L{/.v_z\
TcRnjsY$
i|=}zR
<div V&GFGds
*~fN^{B'!
Up/1c:<J
<5L!.Ci
class="text">right<p>1</p><p>1</p><p>1</p><p>1</p><p>1</p></div> vqL{~tR
n1$##=wK]
q2,@>#
s$Roe(J
</div> _NZ)
n)
iY(hGlV
Y*"%;e$tg
+mxs jcq0
<div id="left"> XFBk:~}sI
nP0}vX)<
c&R .
W#??fae
<div class="text">left</div> %\-+SeC
~\ iuV
dQizM^j
f \4Qp
</div> O;,k~
\,(t P:o
u1<xt1K
$p9XXZ"*
</div> _q8s 7H
Xi0/Wb h\
X\$M _b>O
6tnAE':
</div> 8zpK;+
"@ox=
^?juY}rZ=|
h[B
Ft{x
<div id="footer">footer</div> +)7NWR\
s&fU|Jk8
z?7s'2w&{
0+S:2i/G
</body> ,U<Ku*}B
zu;Yw=cM)
`zep`j&8^
VD=$:F]
</html>