Answers:
你是这个意思?
<style type="text/css">
.bgimg {
background-image: url('../images/divbg.png');
}
</style>
...
<div class="bgimg">
div with background
</div>
您可以使用CSS的background
属性来做到这一点。有几种方法可以做到:
HTML:
<div id="div-with-bg"></div>
CSS:
#div-with-bg
{
background: color url('path') others;
}
HTML:
<div class="div-with-bg"></div>
CSS:
.div-with-bg
{
background: color url('path') others;
}
HTML:
<div style="background: color url('path')"></div>
哪里:
background
CSS属性是该语法中所有background-xxx属性的连接:
背景: 背景色 背景图像 背景重复 背景附件 背景位置 ;
资料来源:w3schools
使用像..
<div style="background-image: url(../images/test-background.gif); height: 200px; width: 400px; border: 1px solid black;">Example of a DIV element with a background image:</div>
<div style="background-image: url(../images/test-background.gif); height: 200px; width: 400px; border: 1px solid black;"> </div>
您可以简单地添加一个id为img src的属性:
<body>
<img id="backgroundimage" src="bgimage.jpg" border="0" alt="">
</body>
并在您的CSS文件中(拉伸背景):
#backgroundimage
{
height: auto;
left: 0;
margin: 0;
min-height: 100%;
min-width: 674px;
padding: 0;
position: fixed;
top: 0;
width: 100%;
z-index: -1;
}
<div class="foo">Foo Bar</div>
并在您的CSS文件中:
.foo {
background-image: url("images/foo.png");
}
<div id="imgg">Example to have Background Image</div>
我们需要在样式标签中添加以下内容:
.imgg(
background-image: url('C:\Users\ajai\Desktop\10.jpg');
)