css图片大小(宽度,高度)自适应
百分比大小图片CSS自适应 代码示例:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>百分比大小图片CSS自适应</title>
</head>
<body>
<div id="yt_pic">
<style>
<!--
body {
font-size: 12px;
text-align: center;
margin: 0px;
padding: 0px;
}
#yt_pic{
margin:0 auto;
width:800px;
padding:0;
border:1px solid #333;
}
#yt_pic img{
max-width:600px;
width:expression(document.body.clientWidth>document.getElementById("pic").scrollWidth*9/10? "600px": "auto" );
border:1px dashed #000;
}
-->
</style>
<img src="http://love.dzyouyi.com/upload/201301/20130112000842558.jpg" id="img1" />
</div>
</body>
</html>
|
固定大小图片CSS自适应示例代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>固定大小图片CSS自适应</title>
</head>
<body>
<div id="yt_pic">
<style>
<!--
body {
font-size: 12px;
text-align: center;
margin: 0px;
padding: 0px;
}
#yt_pic{
margin:0 auto;
width:800px;
padding:0;
border:1px solid #333;
}
#yt_pic img{
max-width:600px;
width:expression(document.body.clientWidth > 600? "600px": "auto" );
}
-->
</style>
<img src="http://love.dzyouyi.com/upload/201301/20130112000842558.jpg" id="img1" />
</div>
</body>
</html>
|
css图片大小(宽度,高度)自适应
