我正在研究一种模式,其中有一个图像背景。现在,图像没有填满整个 div。这是我目前在我的 css 中的内容:
CSS:
.modal {
border-radius: 10px;
min-width: 65vw;
min-height: 40vh;
border-width: 5px;
border-style: solid;
border-color: var(--secondary);
background: url("../../../assets/cloudy.png");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
HTML:
<div class="modal"></div>
每当我用颜色替换背景时,它都会起作用。这是背景图像与颜色的当前外观:
我尝试将背景大小更改为包含和 100% 100%。它没有用。
是不是图片有问题?因为图很长。1942 × 478 具体。提前致谢!
我已经在我的笔记本电脑上尝试了大部分图片,它似乎工作得很好。
.modal {
border-radius: 10px;
min-width: 65vw;
min-height: 40vh;
border-width: 5px;
border-style: solid;
border-color: var(--secondary);
background: url("https://media.mnn.com/assets/images/2018/08/CollectionOfCloudsAgainstABlueSky.jpg.653x0_q80_crop-smart.jpg");
background-position: center;
background-repeat: no-repeat;
background-size: cover;
}
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="modal"></div>
</body>
</html>
如果您在代码中放置图像链接而不是本地文件名,我可以提供帮助。但也许它是一个 png 问题,因为顶部和底部可以看到低谷。(我也不能发表评论,所以这是最好的沟通方式,抱歉。)
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句