Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/38.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 如何使用CSS在DIV标签上添加背景图像_Html_Css_Background_Background Image - Fatal编程技术网

Html 如何使用CSS在DIV标签上添加背景图像

Html 如何使用CSS在DIV标签上添加背景图像,html,css,background,background-image,Html,Css,Background,Background Image,我试图用背景图像设置我的DIV,但它对我不起作用。图像根本没有显示出来。我似乎不知道我做错了什么 这是我的密码: <div id="main_wrapper"> <div id="main_content"> </div> </div> 如果有人能帮我解决这个问题,那将非常有帮助。谢谢你抽出时间 您需要将背景尺寸:封面添加到#主包装。这应该可以满足您的需要。您需要将背景尺寸:cover添加到#main_wrappe

我试图用背景图像设置我的DIV,但它对我不起作用。图像根本没有显示出来。我似乎不知道我做错了什么

这是我的密码:

<div id="main_wrapper">
        <div id="main_content">
        </div>
</div>

如果有人能帮我解决这个问题,那将非常有帮助。谢谢你抽出时间

您需要将
背景尺寸:封面
添加到
#主包装
。这应该可以满足您的需要。

您需要将
背景尺寸:cover
添加到
#main_wrapper
。这应该可以满足您的要求。

尝试以下图像大小:

#main_wrapper{
 background: url("img/bar_bkgnd.png");
 background-size: 100% 100%;  // or cover like Ben Dyer states
 background-repeat: no-repeat;
}

对于图像大小,请尝试以下操作:

#main_wrapper{
 background: url("img/bar_bkgnd.png");
 background-size: 100% 100%;  // or cover like Ben Dyer states
 background-repeat: no-repeat;
}

只需检查工作示例:

#main_包装
应大于
#main_内容
,并尝试


您可以使用更有效的
em
%
自动
和其他功能。

只需查看工作示例:

#main_包装
应大于
#main_内容
,并尝试

您可以使用更有效的
em
%
auto
和其他功能。

在您的主要内容中,添加以下内容:

 margin: auto;
在您的#主内容中,添加以下内容:

 margin: auto;

背景大小:cover
键/值添加到包装器中的css中。应该会修复它。在包装器中将
背景大小:cover
键/值添加到css中。你应该把它修好。