捌玖网络工作室's Archiver

admin 发表于 2007-12-8 14:55

在DIV下图片自适应的解决方法

以前的解决方法主要是利用js来实现,但用过的人都知道该办法有点繁琐。还有一种是在外部容器定义over-flow:hidden。但这种办法只会切割图片而不会自动适用。+gU2g6}Kr;[
关键在于:max-width:780px;以及下面那行。!u/}_ d*LAH
[b]固定像素适应:[/b]
f+^W+S)\W0xe Gc
Ip*QjtA dotted; TABLE-LAYOUT: fixed; BORDER-TOP: #cccccc 1px dotted; BORDER-LEFT: #cccccc 1px dotted; BORDER-BOTTOM: #cccccc 1px dotted" cellSpacing=0 cellPadding=6 width="95%" align=center border=0>  以下是引用片段:
;V%A'Ptn <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> y c6v+Zx#ce#{
<html xmlns="http://www.w3.org/1999/xhtml";> ~M'Ga!bS[e-SX
<head>
&i'w}.BD x,t&^3?x <meta http-equiv="Content-Type" c /> #F$e8|fg4?Z Cy
<title>css2.0 VS ie</title>
8j c7I~8j"`-~q <style type="text/css"> uRC*X,n4eN,k
<!--
$X9E^2A/^g+r body { s_*F bJx8v ] Q
font-size: 12px;
8_KW9er$T text-align: center;
Gh/Yq^? margin: 0px;
UB xc9D3cGWF#V padding: 0px; &T'Xx2b{8sGe
}
/xL8_JS+Wd #pic{
9e]9R d1| J Q y   margin:0 auto; JY??HH }M
  width:800px;
Z9^"k3~(Z n{Ky   padding:0; V#Q(jv4Q m/G
  border:1px solid #333; gm&]ds"c
  } h D`+et8p
#pic img{ EK P p@$^.x$F^N
    max-width:780px; J:^6H%bR9hq9ae2a
width:expression(document.body.clientWidth > 780? "780px": "auto" ); &A3g UW#A4AI7l
border:1px dashed #000; )Q,Ax~p j u{1`
}
Go%r Y2Wh)I -->
a$LSS(vvz </style>
Wx#dFi:?%a </head>
'g0Ud0vM <body>
9^S.F1x#DsV1VOCb <div id="pic"> *Q? @:o:hB-\L"Q
<img src=[url=http://webclub.net.cn/images/Beijing2008/logo.gif]http://webclub.net.cn/images/Beijing2008/logo.gif[/url]>
I B2S? O.D:[$K </div> qzSO6W{6M(] ?
</body>
)[-CG6SWZ*y </html> 1iba8i7F+?` `0r
qTi0Mp`K d
百分比适应:
8qA^,z `+lb&[+V 以下是引用片段:#Y{b oO)X+c|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
9H@)lyh;U vp"}~ <html xmlns="http://www.w3.org/1999/xhtml";>
1_9U2djl#RTv <head> r3o[-`Gsa
<meta http-equiv="Content-Type" c />
o8n.rB]Qp-` <title>css2.0 VS ie</title>
{?+s'Q]h-U pd7{ <style type="text/css">
n\!j4O8h$O#S N <!--
3n? l6H(@1R;\` body { WT.X0_:s;II
font-size: 12px;
:B'r0X[-Z l1T text-align: center;
w6^/x,~-t]d margin: 0px;
5W bh{'|R} padding: 0px;
\ D$xtR A g2?+m3L } !C9[-hiw b2b+IY
#pic{
v0f.I4W UN   margin:0 auto; 8['Y^ S!uG^/h;L
  width:800px;
$S(K}fE n]Q"?   padding:0;
!r6m1Jb(p3Kj4V1U ]   border:1px solid #333;
#\!PBf}@M5oC   }
R!Fs D\aI_v #pic img{
1VFD#y:Jh~+fE     max-width:780px; %H!G8TU*k BF#H
width:expression(document.body.clientWidth>document.getElementById("pic").scrollWidth*9/10? "780px": "auto" ); 4l3r#A*Q x V
border:1px dashed #000;
:F;fi}Hy0cI }
B/fm-L)G n*[(HvYL --> /Wd ?6vShf
</style> $b&n#G3w9A D'ylQ
</head> M*i$TJp.k"Y
<body> '[G wA[-Y
<div id="pic"> +T,WZ"}7@,EE
<img src=[url=http://webclub.net.cn/images/Beijing2008/logo.gif]http://webclub.net.cn/images/Beijing2008/logo.gif[/url]>
(~ k-_%k1gu0B+@O4C4O </div> 1W$f6H5c-tAo9E@
</body> |oS @L,EP#U~m
</html>

页: [1]
【捌玖网络】已经运行:


Powered by Discuz! Archiver 7.2  © 2001-2009 Comsenz Inc.