简体   繁体   English

背景图像无法拉伸以覆盖平板电脑的高度

[英]Background Image not stretch to cover tablet Height

I have a large enough background image for my site but when I see it using my table the image does not cover the entire screen. 我的网站背景图片足够大,但是当我在桌子上看到背景图片时,该图片无法覆盖整个屏幕。 You can see the grey background (generated by browser i assume) at the bottom. 您可以在底部看到灰色背景(由我假设的浏览器生成)。 Also, if i expand articles on my page, the height increases but not the image it goes to the center 另外,如果我在页面上展开文章,则高度会增加,但图像不会居中

This is the site im testing: http://www3.carleton.ca/clubs/sissa/html5/ 这是我正在测试的网站: http : //www3.carleton.ca/clubs/sissa/html5/

CSS: CSS:

body{
    width: 100%; /*always specify this when using flexBox*/ 
    height:100%;
    display: -webkit-box;
    display: -moz-box;
    display: box;
    text-align:center;
    -webkit-box-pack:center; /*way of centering the website*/
    -moz-box-pack:center;
    box-pack:center;
    background:url('images/bg/bg14.jpg') no-repeat center center fixed;
    -webkit-background-size: cover;
    -moz-background-size: cover;
    background-size: cover;
    font-family: Arial, Helvetica, sans-serif;
    font-size: 13px;
}

在此处输入图片说明

I solved this issue by changing rule -webkit-background-size: cover to -webkit-background-size: cover !important 我通过将-webkit-background-size: cover更改为-webkit-background-size: cover !important来解决了这个问题

Seems to work thus far. 到目前为止似乎工作正常。

I've had more success using percentages with background-size . 使用带有background-size百分比,我获得了更大的成功。

element {
  background:url(xyz.jpg) no-repeat center center;
  background-size:100% 100%;
  /* OR */
  background-size:100% auto;
  /* OR */
  background-size:auto 100%;
}

I found a solution by putting a height and width on the HTML. 我通过在HTML上放置高度和宽度找到了解决方案。 The other solutions wouldn't make the background fill the screen on my Nexus 10. 其他解决方案无法使背景充满我的Nexus 10的屏幕。

html { 
    background: url(backgroundImg.jpg) no-repeat center center fixed; 
    -webkit-background-size: cover;
    -moz-background-size: cover;
    -o-background-size: cover;
    background-size: cover;
    height: 100%;
    width: 100%;
}

If I hit problems on an iPad, then I'll try adding back in the !important on those. 如果我在iPad上遇到问题,则尝试在这些问题上重新添加!important。 Just want to see if I can go without. 只想看看我是否可以没有。

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

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