Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/80.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 为什么背景图像显示在屏幕的一半上?_Html_Css_Background Image - Fatal编程技术网

Html 为什么背景图像显示在屏幕的一半上?

Html 为什么背景图像显示在屏幕的一半上?,html,css,background-image,Html,Css,Background Image,我的背景图片并没有覆盖页面上的所有内容,而是只覆盖了屏幕的一半 具有相同图像的相同代码在我的另一页上正常工作。 唯一不同的是,我在这个页面上有很多内容,但我认为这并不重要 问题在哪里 提前谢谢 html 试试这个代码 background-size:100% 100%; 试试这个 background-image: url(path-to-file/img.jpg); background-repeat:no-repeat; background-position: center center

我的背景图片并没有覆盖页面上的所有内容,而是只覆盖了屏幕的一半

具有相同图像的相同代码在我的另一页上正常工作。 唯一不同的是,我在这个页面上有很多内容,但我认为这并不重要

问题在哪里

提前谢谢

html

试试这个代码

background-size:100% 100%;
试试这个

background-image: url(path-to-file/img.jpg);
background-repeat:no-repeat;
background-position: center center;
您好,您只需尝试以下CSS片段


我猜你在写身份证时漏掉了一个双引号

<html>
<head>
</head>
<body>
<div id="main">
<!--Here i have multiple sections-->
</div>
</body>
</html>

此方法有效

  body
{
margin:0px;

width: 100%;
    height: 100%;

}
#main {
     background-image: url('download.jpg');
    width: 100%;
    height: 100%;
    background-size: 100% 100%;
    background-repeat: no-repeat;
}

这里您使用的是psudeo元素before。psudeo元素before的功能如下所示。 它会在第一个索引处附加一个子节点。在您的情况下,您试图在div元素之前附加一个图像。这与您的整个身体不符

要使图像适用于您的全身,请尝试以下方法:

 body
{
margin:0px;
width: 100%;
height: 100%;
background: url(../..//images/3.jpg) repeat left top;
}
然后卸下psudeo元件:在

#main {
   position: relative;
   /*Other CSS Properties*/
}

背景图像:url(文件/img.jpg的路径);背景位置:中心。。。。我的问题中已经有了这些代码行。再见,他们不在那里,看这个。。。背景:url(../..//images/3.jpg)中心固定;很抱歉没有注意到URL中的双斜杠显示为灰色。是否要在div中或div之前添加背景图像?我想在整个页面中添加背景图像,或者我的所有内容都应显示在该图像中。你是说屏幕的一半,或者,您只能看到一半的图像,那么为什么要使用psudeo运算符:before?它不会在div元素之前添加图像。如果要将背景图像应用于页面,请将其应用于body元素background size:cover;它用图像覆盖整个块而不受挤压;如果你看不到完整的图像,请使用background-contain。不,亲爱的,那是错误地错过了。。。请参阅问题正文{边距:0px;宽度:100%;高度:100%;}主{背景图像:url('download.jpg');宽度:100%;高度:100%;背景大小:100%100%;背景重复:无重复;}
  body
{
margin:0px;

width: 100%;
    height: 100%;

}
#main {
     background-image: url('download.jpg');
    width: 100%;
    height: 100%;
    background-size: 100% 100%;
    background-repeat: no-repeat;
}
 body
{
margin:0px;
width: 100%;
height: 100%;
background: url(../..//images/3.jpg) repeat left top;
}
#main {
   position: relative;
   /*Other CSS Properties*/
}