简体   繁体   English

反拉伸和背景尺寸:封面

[英]Backstretch and background-size: cover

I'm currently using CSS for full screen background one my single page website (composed of several DIVs of 1300px height under each other). 我目前在单页网站上使用CSS作为全屏背景(由相互之间1300px高度的几个DIV组成)。 It works well, the background image is full screen on the visible part of the page, but it doesn't work on ipad. 效果很好,背景图像在页面的可见部分是全屏的,但在ipad上不起作用。 The issue with backstretch is that if I include this code 拉伸的问题是,如果我包含此代码

 <script>
 $("#medias").backstretch("../images/bg-18.jpg");

within my "medias" DIV, the background image covers the full size of my DIV (so 1300 height * width) which is not what I want it to cover the browser window only Many thanks 在我的“媒体” DIV中,背景图像覆盖了我的DIV的全部大小(即1300高度*宽度),这不是我希望它仅覆盖浏览器窗口的大小。

Example of a DIV with CSS method: 带CSS方法的DIV示例:

#medias {
    height: 1300px;
    background: #8aba56;
    padding-top: 150px;
    background: url(../images/bg-18.jpg) no-repeat center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    -ms-background-size: cover;
    -o-background-size: cover;
}

I ended up using backstretch initially because the css didn't seem to work on ipads. 我最初使用了backstretch,因为CSS似乎无法在iPad上使用。 Exactly as you've described. 正是您所描述的。 However, oddly enough, after experimenting with the CSS, and changing this: 但是,奇怪的是,在尝试了CSS并进行了以下更改之后:

background-image: url('background.jpg'); 背景图片:url('background.jpg');

to, 至,

background-image: url ('www.imgur.com/background.jpg') 背景图片:网址('www.imgur.com/background.jpg')

The background worked on the iPad. 背景在iPad上起作用。 It seemed that changing the background-image location to a direct url the iPad was able to produce the image. 似乎将背景图像的位置更改为直接网址,iPad即可生成图像。 So, try uploading your image to a temporary server (like imgur), and then changing the link in your CSS, to the imgur link. 因此,请尝试将图像上传到临时服务器(例如imgur),然后将CSS中的链接更改为imgur链接。

Strangely enough it worked for me. 奇怪的是它对我有用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM