捌玖网络工作室's Archiver

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

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

以前的解决方法主要是利用js来实现,但用过的人都知道该办法有点繁琐。还有一种是在外部容器定义over-flow:hidden。但这种办法只会切割图片而不会自动适用。^~6tO m
关键在于:max-width:780px;以及下面那行。
zl&EX U [b]固定像素适应:[/b]
CB7^Nng m
c;F1ZI#fQ\.g 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>  以下是引用片段:+gfJ!JrYH
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> .v#s|;l ]1Z Az,e
<html xmlns="http://www.w3.org/1999/xhtml";>
"{9|4C3v"g <head> (`+Kq3ybP3o%SJ J
<meta http-equiv="Content-Type" c />
D!V.c(d s:r#G <title>css2.0 VS ie</title>
g#MP(y cT6Z <style type="text/css">
kv6l"d;oE <!--
jEU:w2gPH M body {
A gNcU-L$So'IQ\ font-size: 12px; -A;?T;u.n+k&W7d)s3]
text-align: center;
'gG _9] G:I!Lw%A*v/m margin: 0px; 4q%~ n6r-L*K1R3n
padding: 0px;
xU!qB5i6q"c }
K'JZd"g#V #pic{
G Ru m2Q   margin:0 auto;
Z^8b5V(S   width:800px;
zLD*f|@ V5oJp   padding:0;
,}^ZD5Wy   border:1px solid #333; Q*x5h+b QZJ9w
  } du9p n5^
#pic img{
2?'{E1V?l|m     max-width:780px;
-u`CA:q(EF width:expression(document.body.clientWidth > 780? "780px": "auto" ); SGfop4J
border:1px dashed #000;
:i CMI w _1n"w }
DI.\.F9rQ --> %z H!bB1]u-H&m \ sZ
</style>
!M~1t2@M o6} </head> oY!Ysr"dg
<body> i(Q'y5WE0l]T
<div id="pic">
8g?9C"X2h Cf'R+GF)M;m U%B <img src=[url=http://webclub.net.cn/images/Beijing2008/logo.gif]http://webclub.net.cn/images/Beijing2008/logo.gif[/url]>
T sBH6o:K2h~ x </div>
q bF;N%TT!W T{2fi </body> )CCd5s^SNJ
</html> Q tjF4J+QS
a4G.|2m#x[
百分比适应:
(I$EY~[(S wr.~ 以下是引用片段:(R%z `v Hq'S%NQ
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> 5K}UNWdK&y[^
<html xmlns="http://www.w3.org/1999/xhtml";> (Onu#Vdf
<head> JO{O{
<meta http-equiv="Content-Type" c /> y.D @.gKP
<title>css2.0 VS ie</title> 7y _7p3lC$Oi
<style type="text/css"> I:R wf.i
<!-- P r-l:xA |5r
body {
0H'`%o6|:U6M!}K*P["Q font-size: 12px; #Ro2Fd TD aP
text-align: center; 5WfdG4k4R?|u#f6H
margin: 0px; +I1HgT/XQr*`
padding: 0px; 7^et+a/~/~aC3S&_2C
}
'ri#C5[5r6o*MR #pic{
!{T4VK#D   margin:0 auto;
!| ?KC;^   width:800px;
No_5Y-?2k$k   padding:0;
WNY w L   border:1px solid #333; U-]}*n,b!k
  } !pTm u w3zH^
#pic img{ $RR1r0U[R|Y
    max-width:780px;
FAW tp\@/N H width:expression(document.body.clientWidth>document.getElementById("pic").scrollWidth*9/10? "780px": "auto" ); WKI~1Affi:E4i
border:1px dashed #000;
%S0}Nl]7o7M9a } `N\B0iN.kf Q
--> M$N}@#d*^-A
</style>
x yS1KVI </head>
h+D-Bg+z)V2I-I <body> CX!h/V*` T
<div id="pic">
rc]n'oJ+G <img src=[url=http://webclub.net.cn/images/Beijing2008/logo.gif]http://webclub.net.cn/images/Beijing2008/logo.gif[/url]>
b]^JLs7Y~ </div> 7]8er*X$Y2S4U,pO-q
</body>
(l{1O"rN u1c^'D \t </html>

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


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