【发布时间】:2016-07-29 05:12:46
【问题描述】:
我在正确定位背景图片时遇到问题。它可以在桌面上运行,即使我调整窗口大小以模拟手机,它也能正确显示,但是当我实际访问手机上的网站(在 Android/Chrome 和 iOS/Safari 上测试)时,它似乎忽略了背景位置属性。
有问题的 CSS:
.blur {
background:
/* top, transparent blue, faked with gradient */
linear-gradient(
rgba(43, 43, 43, 0.1),
rgba(43, 43, 43, 0.1)
),
/* bottom, image */
/* BACKGROUND IMAGE */
url('https://suzannecowan.ca/wp-content/uploads/2016/04/2015-10-20-macleans-2-1.jpg');
background-attachment: fixed;
background-position: -350px -150px;
background-position-x: -350px;
background-position-y: -150px;
background-size: cover;
background-repeat: no-repeat;
background-color: #2b2b2b;
overflow: auto;
}
@media (min-width: 40em) {
.blur {
background:
/* top, transparent blue, faked with gradient */
linear-gradient(
rgba(43, 43, 43, 0.1),
rgba(43, 43, 43, 0.1)
),
/* bottom, image */
/* BACKGROUND IMAGE */
url('https://suzannecowan.ca/wp-content/uploads/2016/04/2015-10-20-macleans-2-1.jpg');
background-attachment: fixed;
background-position: -350px 0;
background-size: cover;
background-repeat: none;
}
@media (min-width: 50em) {
.blur {
background:
/* top, transparent blue, faked with gradient */
linear-gradient(to right,
rgba(43, 43, 43, 0.1),
rgba(43, 43, 43, 0.1)
),
/* bottom, image */
/* BACKGROUND IMAGE */
url('https://suzannecowan.ca/wp-content/uploads/2016/04/2015-10-20-macleans-2-1.jpg');
background-attachment: fixed;
background-position: -250px 0;
background-size: cover;
background-repeat: none;
}
我已经搜索了解决方案,并发现了两个对过去有所帮助的建议:添加 background-position-x 和 background-position-y 没有帮助,并将背景图像移出 body 并移到不同的容器中(在这种情况下为.blur)也没有帮助。
提前感谢您提供的任何建议。
【问题讨论】:
-
您是否尝试过为
@media (min-width: )使用像素量?我从未见过em用于此目的。 -
@theblindprophet 我一直使用
em,之前从未遇到过问题,但我按照您的建议更改了它,没有任何区别。 -
特别令人沮丧的是,我在 shaun-francis.com 上使用了相同的技术并且效果很好,所以我现在不知道自己做错了什么。
-
我不知道你是否喜欢额外的工作因素,但我有一个 100% 工作的资源:@987654322@
-
移除背景尺寸:封面属性
标签: html css responsive-design background-image background-position