gpt4 book ai didi

html - CSS 背景位置不适用于移动设备

转载 作者:太空宇宙 更新时间:2023-11-04 02:31:10 26 4
gpt4 key购买 nike

我在正确定位背景图像时遇到问题。它在桌面上工作,即使我调整窗口大小时模拟手机它也能正确显示,但当我实际访问我手机上的网站时(在 Android/Chrome 和 iOS/Safari 上测试)它似乎忽略了背景位置属性(property)。

有问题的 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-xbackground-position-y 但没有无济于事,将背景图像从 body 移到另一个容器(在本例中为 .blur)也无济于事。

网站是:https://suzannecowan.ca/ .

提前感谢您提供的任何建议。

最佳答案

将背景图片设置为 cover意味着它会想要拉伸(stretch)到屏幕的高度,这意味着在小型设备上你会看到非常狭窄的 View 。就个人而言,我要么将图像调整得更高更薄,以便它更适合移动屏幕,要么将背景大小设置为 100% auto ,恕我直言,这看起来不错。

关于html - CSS 背景位置不适用于移动设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36491129/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com