Div 背景图像消失

Rak*_*esh 1 html css

嗨,我正在尝试将图像作为背景添加到 div。它在窗口最大化时工作,但是当我改变窗口大小时,图像消失。

你能告诉我我哪里出错了。

background-image: url('../Images/IPCC-Tile.jpg');
background-color: #FFFFFF;
background-repeat: no-repeat;
background-position: center center;
position: absolute;
width: 15%;
height: 35%;
top: 30%;
left: 2%;
overflow:visible;
Run Code Online (Sandbox Code Playgroud)

谢谢你。

meg*_*382 5

这应该有效:

background-image: url('../Images/IPCC-Tile.jpg');
background-color: #FFFFFF;
background-repeat: no-repeat;
background-position: center center;
background-size:contain; 
position: absolute;
width: 15%;
height: 35%;
top: 30%;
left: 2%;
overflow:visible;
Run Code Online (Sandbox Code Playgroud)

设置background-sizecover或的值,contain没关系。