CSS Background Images not loading

后端 未结 5 835
独厮守ぢ
独厮守ぢ 2021-01-06 17:23

I\'ve got a very strange bug in chrome recently that is when you load the page first time, or in incognito mode that none of the background images show.

when you the

相关标签:
5条回答
  • 2021-01-06 17:46

    Just to note.

    The problem had been solved.

    The issue was that the browser downloads all the css background images last. So if you refresh the page before its finished downloading the images, when the page loads again it loads from the cache. but because the images did not fully download they dont show correctly.

    0 讨论(0)
  • 2021-01-06 17:52

    First of all, fix these:

    backg1round-color: #c7dfe3;
    backg1round-color: rgba(255,255,255,0.67);
    

    If images is a subfolder then use

    url('images/logo-bg2.jpg');
    

    instead of

    url('/images/logo-bg2.jpg');
    

    in main.css

    0 讨论(0)
  • 2021-01-06 17:52
    Change css class as:
    
    
    #nav
    {
        background-image: url(../images/logo-bg2.jpg);
        height: 180px;
    }
    
    0 讨论(0)
  • 2021-01-06 18:02

    Owen,

    I still see this problem on the application that I'm working on. I know this is also a hacky solution, but it's a little less hacky than the jquery solution that you had posted. I simply threw a version number based on time after the css include and it

    e.g. " rel="stylesheet" type="text/css" />

    I know that this causes the css to never be cached, but I have not found any other solution.

    0 讨论(0)
  • 2021-01-06 18:06

    Try this instead. Not tested though;

    $('*').each(function(){
    var bg = $(this).css('background');
    $(this).css('background', 'none');
    $(this).css('background', bg);
    });
    

    And make relevant changes (ie, background-image to background) in your CSS also.

    OR try;

    $('*').each(function(){
    var bg = $(this).css('background-image');
    $(this).css('background-image', 'none');
    $(this).css('background-image','url(bg)'); // or try url("bg") i am confused :P
    });
    

    From some search and research I came to a conclution;

    The way I would tackle this is with classes. Have a separate CSS classes for each of the states, then simply use jQuery to change the class. This would ensure that all of the images are actually downloaded and available when you set the class -- which is where I think Chrome is failing (probably all WebKit browsers would do this)

    0 讨论(0)
提交回复
热议问题