Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/google-cloud-platform/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 将背景图像设置为div_Html - Fatal编程技术网

Html 将背景图像设置为div

Html 将背景图像设置为div,html,Html,我尝试将我的页面编码如下: <div class="Conttent-Group"> <div class="Conttent-Group-Body"> <div class="Conttent-Body-Right"> <div class="Conttent-Body-Left"> <h1><a href="#" style="text-deco

我尝试将我的页面编码如下:

<div class="Conttent-Group">
    <div class="Conttent-Group-Body">
        <div class="Conttent-Body-Right">
            <div class="Conttent-Body-Left">
                 <h1><a href="#" style="text-decoration:none">News operations</a></h1>
            </div>
        </div>
    </div>
</div>
但是当运行我的代码时,我只看到背景色

* { background-color: # 006; }

而不是我设置的背景图像。如何修复此问题并显示图像?

当前您使用的是
*{background color:#006}
*选择器
针对你这边的每个元素,这就是为什么每个背景颜色都是相同的

使用图像作为背景时,首先查找其文件路径:

/index.html
/style.css
/images/
/images/picture1.jpg
/images/picture2.jpg
如果您想将图片作为目标,您必须始终选择与css文件相关的文件路径。例如,在本例中,您的路径是
images/picture1.jpg
。尽管要注意文件结构中的大小写字母(如
图像
图像
)或不需要的空格

使用此选项,您可以设置背景图像,并添加多个变量,如:

background-image: url(images/picture1.jpg); /* no spaces inside your url */
background-repeat: no-repeat; /* or "repeat-x", "repeat-y" */
background-size: cover; /* for a fullscreen background */
background-color: #fff /* for everything your background images does not cover */

/* or combine them all into one */
background: url(images/picture1.jpg) no-repeat top center;


此外,代码中有很多错误。也许你应该考虑刷新基础知识,使用在线助手或者你会发现的其他东西。< /P>请编辑你的问题中的代码。
background-image: url(images/picture1.jpg); /* no spaces inside your url */
background-repeat: no-repeat; /* or "repeat-x", "repeat-y" */
background-size: cover; /* for a fullscreen background */
background-color: #fff /* for everything your background images does not cover */

/* or combine them all into one */
background: url(images/picture1.jpg) no-repeat top center;