背景大小CSS属性在safari上的IOS设备中无法正常工作



我有一个主体背景大小集。它在android和windows中运行良好。背景的大小可以。但当我在iphone上加载我的网站时,背景大小——特别是高度——看起来太大了,不能超过5%。背景大小:85%5%;所以宽度是身体的85%,高度是身体的5%,但高度看起来是视口的50%,这很奇怪。为什么这种情况只发生在iphone上。我认为添加webkit前缀是行不通的。ios和safari有什么问题吗。。。?我是不是错过了什么。。。?如果你知道发生了什么,请帮我解决这个问题。提前谢谢。。。

CSS

body 
{
background: -webkit-linear-gradient(left, white, white, #98AEC4, white, #98AEC4, white, white) fixed;
background-repeat: no-repeat;
background-position: top center; 
background-size: 85% 5%; 
}

浏览器如何计算机身背景高度。。?其他浏览器采用视口高度,但在iphone中,参数不匹配。。。

使用fixed的方式是background-attachment: fixed;的快捷方式。

此属性没有得到很好的支持。检查我可以使用吗以了解当前的支持。

高度设置为100%的固定位置元素的行为与具有background: .... fixed;属性的元素类似。

因此,您不应该在body上拥有属性,而应该以这种方式创建div(请参阅具有background类的属性(:

<head>
<style>
.background {
position: fixed;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
background: -webkit-linear-gradient(left, white, white, #98AEC4, white, #98AEC4, white, white);
background-repeat: no-repeat;
background-position: top center; 
background-size: 85% 5%; 
}
.long-div {
height: 100vh;
}
</style>
</head>
<body>
<div class="background"></div>
<div class="long-div">Scroll down to see it how it behaves on scroll 👇🏻</div>
<div class="long-div">Here you are at half of the scroll 👇🏻</div>
<div>Here you are at bottom of the scroll.</div>
</body>

你可以在CSS-TRICKS上找到一篇文献丰富的文章——固定背景附件破解。

对于iPhone safari,我认为您必须在媒体查询中添加背景附件

@media (max-width : @iphone-screen){
background-attachment: scroll;

}

最新更新