css - 在 Safari (iOS) 上对图片进行缩放转换
问题描述
问题出在 iPhone 上,在 android 手机上它的代码运行良好。在 Safari 上,背景图片被放大,您可以在下图中看到:
在 Safari 上显示: Safari-view
在 Android 上显示(正确): Android-view
我可以用该代码改进什么?
HTML:
<div id="background">
<h2>Lorem ipsum</h2>
<hr />
<h3>Dolor sit amet</h5>
</div>
CSS:
#background{
height: 92.5vh;
background-attachment: fixed;
background-position: center;
background-repeat: no-repeat;
background-size: cover;
-webkit-animation: mymove 16s infinite;
animation: mymove 16s infinite;
-webkit-animation-timing-function: linear;
animation-timing-function: linear;
background-image: url("gallery/DSC03389n.JPG");
}
@keyframes mymove {
0%{background-image: url("gallery/DSC03389n.JPG");}
46%{background-image: url("gallery/DSC03389n.JPG");}
54%{background-image: url("gallery/DSC03385n.JPG");}
100%{background-image: url("gallery/DSC03385n.JPG");}
from { background-position: 17% 0; }
to { background-position: 70% 0; }
}
@media screen and (max-width: 600px) {
#background{
background-image: url("gallery/DSC03389m.JPG");
}
@keyframes mymove {
0%{background-image: url("gallery/DSC03389m.JPG");}
46%{background-image: url("gallery/DSC03389m.JPG");}
54%{background-image: url("gallery/DSC03385m.JPG");}
100%{background-image: url("gallery/DSC03385m.JPG");}
from { background-position: 17% 0; }
to { background-position: 74% 0; }
}
}
解决方案
这个问题已经存在background-attachment: fixed;
并且已经存在了很长时间,并且非常令人沮丧,cover
并且fixed
是非常常见的 CSS 背景参数。
这里的解决方案是取消fixed
Safari。
我们所做的是使用 PHP 在我们的主体中添加一个设备和浏览器类,并设置它自己的 CSS 声明
.ipad #background,
.safari #background {
background-attachment: scroll;
}
推荐阅读
- math - 乘以 256 有什么作用
- fossil - 使用 Fossil SCM 提供静态文件
- c# - 如何将 HTML 打印为 pdf 文档
- reactjs - 请求的资源上不存在“Access-Control-Allow-Origin”标头 - 尝试使用 Axios 从 REST api 获取数据时
- log4j - Zeppelin log4j 设置不在控制台中打印日志
- javascript - 如何导出要在中间件中使用的 Node MongoDB 驱动程序连接?
- flutter - 字符串 num1=stdin.readLineSync(); 不允许我输入数字,答案显示“空”
- bioinformatics - 蛋白质中原子的杂交(Biopython)
- php - 在子主题中覆盖父主题文件的问题
- vba - 如何在拆分数据库中为 SQL 字符串输入日期变量