如何将图像设置为div的背景并将其“ZOrder”设置为0?

时间:2013-10-25 23:18:38

标签: html css image background-image src

我想将图像设置为div中的背景(并覆盖整个事物),并且仍然能够“在其上面书写”(在背景图像上添加文本)。我尝试将其添加到CSS:

background-image: "http://www.replaster.com/sitebuilder/images/blueWhiteSwirl-758x109.jpg"

......但它没有做任何事。

我不成功的挫折是:

HTML

<div class="CoolTurlockSwimmingPool"> 
    <span>Bla</span>
    <img src="http://www.replaster.com/sitebuilder/images/blueWhiteSwirl-758x109.jpg"></img>Blee
</div>

CSS

.CoolTurlockSwimmingPool {
    background-color: Blue;
    color: WHite;
    font-family: "Segoe UI Light", sans-serif;
}

jsfiddle here:http://jsfiddle.net/X35Ap/

1 个答案:

答案 0 :(得分:1)

您需要在url()

中包含图像的路径
<!DOCTYPE html>

<html lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8" />
    <title>answer</title>
    <style>
        .CoolTurlockSwimmingPool {
            background-color: Blue;
            color: WHite;
            font-family: "Segoe UI Light", sans-serif;
            background-image: url("http://www.replaster.com/sitebuilder/images/blueWhiteSwirl-758x109.jpg");
        }
    </style>
</head>
<body>
    <div class="CoolTurlockSwimmingPool">
        <span>Bla</span>
        Blee
    </div>
</body>
</html>