pho*_*bos 192
你是这个意思?
<style type="text/css">
.bgimg {
background-image: url('../images/divbg.png');
}
</style>
...
<div class="bgimg">
div with background
</div>
Run Code Online (Sandbox Code Playgroud)
Rob*_*bik 40
你可以使用CSS的background功能来做到这一点.有几种方法可以做到:
HTML:
<div id="div-with-bg"></div>
CSS:
#div-with-bg
{
background: color url('path') others;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div class="div-with-bg"></div>
CSS:
.div-with-bg
{
background: color url('path') others;
}
Run Code Online (Sandbox Code Playgroud)
HTML:
<div style="background: color url('path')"></div>
地点:
background CSS属性是该语法中所有background-xxx属性的连接:
背景: 背景颜色 背景图像 背景重复 背景附件 背景位置 ;
资料来源:w3schools
Fla*_*ash 30
是的:
<div style="background-image: url(../images/image.gif); height: 400px; width: 400px;">Text here</div>
Run Code Online (Sandbox Code Playgroud)
jeg*_*esh 12
使用此样式可以获得居中的背景图像而无需重复.
.bgImgCenter{
background-image: url('imagePath');
background-repeat: no-repeat;
background-position: center;
position: relative;
}
Run Code Online (Sandbox Code Playgroud)
在HTML中,为div设置此样式:
<div class="bgImgCenter"></div>
Run Code Online (Sandbox Code Playgroud)
Ana*_*pan 10
使用像..
<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>
Run Code Online (Sandbox Code Playgroud)
小智 7
您可以简单地添加一个id为img src的属性:
<body>
<img id="backgroundimage" src="bgimage.jpg" border="0" alt="">
</body>
Run Code Online (Sandbox Code Playgroud)
并在您的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;
}
Run Code Online (Sandbox Code Playgroud)
<div class="foo">Foo Bar</div>
Run Code Online (Sandbox Code Playgroud)
并在您的CSS文件中:
.foo {
background-image: url("images/foo.png");
}
Run Code Online (Sandbox Code Playgroud)