捌玖网络工作室's Archiver

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

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

以前的解决方法主要是利用js来实现,但用过的人都知道该办法有点繁琐。还有一种是在外部容器定义over-flow:hidden。但这种办法只会切割图片而不会自动适用。ap5jv O
关键在于:max-width:780px;以及下面那行。
$jF'@Z ET0n)Z j [b]固定像素适应:[/b]G7k8ryh3Y

[6y U$x|u0Y}!OA'c8\ 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>  以下是引用片段:
*{T.^&sx[*f3^ z j O <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";>
/QY,Tj |~7h <html xmlns="http://www.w3.org/1999/xhtml";> NH-c{'giP
<head> !L SKn |?6K#P)p
<meta http-equiv="Content-Type" c />
b3S8X(o+FI <title>css2.0 VS ie</title> ;xU({-QA
<style type="text/css">
s E]G3t4o{a <!--
N[I&Z? _%C6O body { nZHy$laDN\c
font-size: 12px; ?TB~l dg
text-align: center; Bn3Ky.Z R
margin: 0px; !?] p` jk
padding: 0px;
*q%\&f1D(nB sO2O }
WB/j$Q[*By #pic{ 7k3aFbS!t
  margin:0 auto; N^VGU
  width:800px;
jC b)\t3c1U{+N(Y m   padding:0; G*~(n}zX'iN @
  border:1px solid #333;
OB+R#B$SY5KD*UF   } jW#^-\U1u,s
#pic img{
\x8Oo&?2@x     max-width:780px; "W M)Z/b!vw}M'z
width:expression(document.body.clientWidth > 780? "780px": "auto" ); ']2o%sjQY
border:1px dashed #000;
u Y/e/{8_ } 5EF%Ko"Irr
--> Tp*B y^R
</style> l7P$Ff)V:BQ@:@
</head>
x N$Y l |f[ <body>
-T Z{p|(`$L <div id="pic"> Owe ?8G
<img src=[url=http://webclub.net.cn/images/Beijing2008/logo.gif]http://webclub.net.cn/images/Beijing2008/logo.gif[/url]>
6DOV:b0l1ZB:f"N$\ </div> bmp~*S(z+zo
</body> ,B/yu}:~
</html> H\KP;DS@tY

u/j7cx^ nU-ot 百分比适应:
vV7eLDso(su 以下是引用片段:Uh9e c9Cf&S`
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> m!y6f|j|ft*O
<html xmlns="http://www.w3.org/1999/xhtml";> y+v%u^4t-x3Hbz
<head> ;\ n5Q,W:o9I
<meta http-equiv="Content-Type" c />
2tNY~ m3]e+? <title>css2.0 VS ie</title> JNK YZ
<style type="text/css">
,qeiK8uO <!-- q Vc6R L&l!hx"t1{O
body { blL?vt[
font-size: 12px;
e\n;c2~ h9t ` text-align: center; 2nY:I[S y
margin: 0px;
7J~ k v$E padding: 0px;
*z.B9?'l ns5Sk%d] }
Q.q!K F:P#I4WS #pic{
bg^&c3|pf   margin:0 auto; 3Z([RD9P-R
  width:800px;
(vES#?g7v5g2B$~R   padding:0; KD ?L:]8FC
  border:1px solid #333; +n.JnlD(Hh{q.f a
  } ?a T4M R#]2qg9r3J*B
#pic img{
v[,^c,gn3s-H_4v\:kBp     max-width:780px;
K@6{xgu width:expression(document.body.clientWidth>document.getElementById("pic").scrollWidth*9/10? "780px": "auto" ); '\$ov&K&c
border:1px dashed #000;
T ZPNyt.]a } |:s&bi.`1s.T`6^
-->
$Ng;@&y-G$H </style> U2Um$i O7EM,J
</head> CA+cU9y&]
<body> Fg&I9K:WM?
<div id="pic">
gP)E.Px0p xC(S] <img src=[url=http://webclub.net.cn/images/Beijing2008/logo.gif]http://webclub.net.cn/images/Beijing2008/logo.gif[/url]> DeRD:v{3@`
</div> ZDS/I`"m~L
</body>
:M LP'D,pN)}b+d(a </html>

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


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