您的位置:首页 > 其它

如何让img设置成为div中的背景图片

2014-12-04 21:06 453 查看
<!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" />
<link rel="stylesheet" href="default.css" type="text/css" />
<script src=".jquery.js" type="text/javascript"></script>
<script type="text/javascript">

</script>
</head>
<body>
<div class="div0">
<div class="div1">
<img src="hello.jpg"/>
<div class="div2">
<table class="table1">
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
<tr>
<td>11111111111111111111111111</td><td>22222222222222222222222</td>
</tr>
</table>
</div>
</div>
</div>
</body>
</html>
.div0{
margin:0 auto;
height:360px;
width:360px;
overflow:hidden;
border:2px solid Black;
}

.div1{
position:relative;
margin:0 auto;
width:350px;
height:300px;
border:1px solid Blue;
}

.div2{
padding-left:10px;
overflow:auto;
height:280px;
border:1px solid Black;
}

.table1 tr td{
border:1px solid Black;
}
img{
position:absolute;
left:0px;
top:10px;
z-index:-1;
width:100%!important;
height:96%!important;
width:expression(this.width > 150 ? "150px" : this.width)!important;}
}


注:在设置absolute时,父类必须是:relative
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: