background-image:url没有显示使用css的背景图像

时间:2012-03-03 17:33:10

标签: html css html5 xhtml

我正在尝试使用background-image设置背景图片:url但它无效。

<!doctype html>
<html>
    <head>
        <title>MyTitle</title>
        <style type="text/css">
            body{
                 <!-- background-color:green; -->
                 background-image:url("background.jpg");
                 <!-- color:white; -->
                }
        </style>
    </head>
    <body>
    </body>
</html>

请帮助!!

2 个答案:

答案 0 :(得分:6)

<!-- comment   -->

是CSS块中无效的注释语法。这可能会破坏你的CSS规则。

尝试

/* comment */

答案 1 :(得分:3)

标签不会嵌套到标签中。

尝试

<!doctype html>
<html>
    <style type="text/css">
        body{
             /* background-color:green; */
             background-image:url("background.jpg");
             /* color:white; */
        }
    </style>
    <head>
        <title>MyTitle</title>
    </head>
    <body>
    </body>
</html>

CSS中的注释定义为......

 /*this is a comment*/