简体   繁体   English

背景图片有时不显示

[英]Background image sometimes not showing

I have a problem with full width background image. 我对全角背景图片有疑问。 Sometimes is loaded ok, but not always. 有时可以加载,但并非总是如此。 Can I prevent this? 我可以预防吗? Is possible, this is in the images size or file kind? 可能是图片大小还是文件类型?

My css: 我的CSS:

   .claim1{
       background: url(../img/naruc.jpg) center center fixed #222;
      -webkit-background-size: cover;
  -moz-background-size: cover;
  -o-background-size: cover;
  background-size: cover;
    display: block;
    height: 360px;
    position: relative;
}

Demo is here: 演示在这里:

http://martinurbanek.cz/demo/bananaclouds_theme#claim1 http://martinurbanek.cz/demo/bananaclouds_theme#claim1

Thanks forward for your help 谢谢你的帮助

I'm not being able to replicate your problem but I guess maybe you would be facing problem due to some CSS issues. 我无法复制您的问题,但我想也许由于某些CSS问题您可能会遇到问题。

I suggest you use jQuery to set you background image as, 我建议您使用jQuery将背景图片设置为

<script>
   $(document).ready(function(){
      $('myOjbect').css('background-image', 'url('../img/naruc.jpg')');
   });
</script>

The reason to use jQuery here is that the ready() function will be executed only after the entire document is loaded and hence it proves reliable. 在这里使用jQuery的原因是,仅在加载整个文档之后才执行ready()函数,因此证明了它的可靠性。

Another reason for using jQuery is that it handles cross-browser issues very well and hence you don't need to add multiple lines to set the background image. 使用jQuery的另一个原因是,它可以很好地处理跨浏览器的问题,因此您无需添加多行来设置背景图像。

这可能会或可能不会影响任何东西,具体取决于您的设置,但是您是否尝试添加100%的width属性?

width: 100%;

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

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