Html 为什么我的照片没有显示在我的div中?

Html 为什么我的照片没有显示在我的div中?,html,css,Html,Css,我在页面上显示了一个图像。这是我的css: body { background: url(./../imgs/beach.png) no-repeat; background-size: 100%; } .background-image { background: url(./../imgs/beach.png) no-repeat; background-size: 100%; } 当我这样做的时候,一切都很好。然后我尝试在div中显示相同的图像。这是我的

我在页面上显示了一个图像。这是我的
css

body {
    background: url(./../imgs/beach.png) no-repeat;
    background-size: 100%;
}
.background-image {
    background: url(./../imgs/beach.png) no-repeat;
    background-size: 100%;
}
当我这样做的时候,一切都很好。然后我尝试在
div
中显示相同的图像。这是我的
html

<body>
    <div class="background-image"></div>
</body>

但现在什么也看不出来。我查看我的网络选项卡,发现
图像可用,但没有显示在页面上。我做错了什么?

因为您只使用背景,所以需要在div本身上设置高度/宽度

.background-image {
    background: url(./../imgs/beach.png) no-repeat;
    background-size: 100%;
    height: */Your Value/*;
}

因为您只使用背景,所以需要在div本身上设置高度/宽度

.background-image {
    background: url(./../imgs/beach.png) no-repeat;
    background-size: 100%;
    height: */Your Value/*;
}

这是因为div的高度为0像素,请给它一些高度,例如:

.background-image {
    background: url(./../imgs/beach.png) no-repeat;
    background-size: 100%;
    height: 100vh;
}

这是因为div的高度为0像素,请给它一些高度,例如:

.background-image {
    background: url(./../imgs/beach.png) no-repeat;
    background-size: 100%;
    height: 100vh;
}

我建议删除背景尺寸:100%。。而是将高度和宽度添加为100%

 body {
        background: url(./../imgs/beach.png) no-repeat;
        height: 100%;
        width: 100%;
    }

我建议删除背景尺寸:100%。。而是将高度和宽度添加为100%

 body {
        background: url(./../imgs/beach.png) no-repeat;
        height: 100%;
        width: 100%;
    }

当它连接到身体上时,为什么我不必给它一个高度?这里有一个很好的参考:当它连接到身体上时,为什么我不必给它一个高度?这里有一个很好的参考:我不能用
%
表示宽度。我必须设置一个特定的宽度,否则什么也看不见。@jhamm,真是个讨厌鬼。。试试看这是否管用正文{height:100%;width:100%;}.background图像{background:url(“Desert.jpg”)不重复;height:inherit;width:inherit;}`我不能用
%
表示宽度。我必须设置一个特定的宽度,否则什么也看不见。@jhamm,真是个讨厌鬼。。试试看这是否管用正文{height:100%;width:100%;}.background图像{background:url(“Desert.jpg”)无重复;height:inherit;width:inherit;}`