我遇到了一个问题,我的网站在笔记本电脑(chrome和safari)上显示了一个背景图像,但当我在手机上使用相同的浏览器时,背景图像却没有出现,我不知道为什么?
下面是我的CSS:
#callToAction
{
padding-top: 80px;
padding-bottom: 80px;
text-align:center;
background-image:url(../img/17545.jpg);
background:url(../img/17545.jpg);
background-position:center;
background-size: cover;
background-attachment: fixed;
}
实际图像大小为1280x475
如果你想亲眼看一看,可以登陆我们的网站https://www.metis-online.com,上面是“行动呼吁”的背景图片,上面写着“今天获得认证”。
这对我来说很有效,我认为因为你的背景尺寸
是封面
,所以左右两边都在视区之外,而且是白色的(如果这就是你说的“不出现”的意思的话)。
请尝试以下操作:
#callToAction
{
background-size: contain;
}
图像没有出现,因为封面显示了图像的白色区域
在媒体查询中使用后续代码
背景大小:100%100%;
或者这个
背景-大小:150VW 100VH
#callToAction {
padding-top: 80px;
padding-bottom: 80px;
text-align: center;
background-image: url(../img/17545.jpg);
background: url(../img/17545.jpg);
background-position: center;
background-size: 100% 100%; /* <-- Replace Cover with 100% */
background-attachment: fixed;
background-repeat: no-repeat;
}
css中的CONTAIN命令根据您定义的框大小或您的屏幕比例调整图像大小,而COVER命令使用您我定义的全部空间,不管图像是否适合屏幕,因此CONTAIN命令将正常工作