1

I am developing a website in which I have used the background-attachment:fixed property. It's working fine in Firefox, but the image is not fixed. In Chrome it's behaving normal. Here is code:

CSS:

.AboutBg
{
    background-attachment: fixed;
    background-image: url("../Images/LandingPage/smart.jpg");
    background-position: 0 0;
    background-repeat: repeat;
    background-size: cover;
    height: 90%;
    position: absolute;
    width: 100%;
}

HTML:

<div class="AboutBg"></div>
honk
  • 9,137
  • 11
  • 75
  • 83
Kamdhenu Gaiya
  • 15
  • 1
  • 1
  • 6

11 Answers11

15

I just had a similar issue, my cover + fixed was not working and images were disappearing on chrome and was able to solve it like this:

Crawl to higher node definitions and disable some of the CSS properties that may have conflicts, in my case for example, there was a:

backface-visibility: hidden at the <body> level that was causing it. This was being introduced by the animate.css framework.

Sorry its not a concrete answer but at least this provides some idea of how to debug your css code.

Juan Carlos Moreno
  • 2,754
  • 3
  • 22
  • 21
2

The Above Code should work with Chrome For Windows ,

Just try including the vendor prefix

-webkit-background-size: cover !important;

And give it a try

epynic
  • 1,124
  • 2
  • 14
  • 26
2

nothing was working for me, and finally this did the trick with no reasoning behind :)

-webkit-background-size: cover !important;
-moz-background-size: cover;
-o-background-size: cover;
background-size: cover;
background-attachment: fixed !important;
position: static !important;
z-index: -1 !important;

This is working for me in both firefox and chrome. Hope that helps.

rosnk
  • 1,068
  • 1
  • 14
  • 36
1

Although this is coming a bit late, by adding the css style below seems to fix it for me.

html, body { 
-webkit-transform: translate3d(0px, 0px, 0px);
}
sabatino
  • 74
  • 4
1

This fixed my problem:

.section{ position: static; }  

(was position: relative)

blurfus
  • 13,485
  • 8
  • 55
  • 61
1

@sabatino's answer is right, but this will destroy the background-attachment:fixed bahavior in Firefox, because they also interpret -webkit prefixed properties - for whatever reason.

So you have to override it like this to make it work in both browsers:

-webkit-transform: translate3d(0px, 0px, 0px);
-moz-transform: none;
Thomas
  • 41
  • 4
0

A late answer but I came around with this and somehow I made a hack for this one.

The idea was to create an inner element which will hold the background-image and will act same as background-attachment:fixed property.

Since this property makes the background image position relative to the window we have to move the inner element within it's container and this way we will get that effect.

var parallax_container = $(".parallax_container");
/*Create the background image holder*/
parallax_container.prepend("<div class='px_bg_holder'></div>");
$(".px_bg_holder").css({
    "background-image" : parallax_container.css("background-image"), /*Get the background image from parent*/
    "background-position" : "center center",
    "background-repeat" : "no-repeat",
    "background-size" : "cover",
    "position" : "absolute",
    "height" : $(window).height(), /*Make the element size same as window*/
    "width" : $(window).width()
});
/*We will remove the background at all*/
parallax_container.css("background","none");
parallax_container.css("overflow","hidden");/*Don't display the inner element out of it's parent*/
$(window).scroll(function(){
    var bg_pos = $(window).scrollTop() - $(".parallax_container").offset().top; /*Calculate the scrollTop of the inner element*/
    $(".px_bg_holder").css({
        "margin-top" : bg_pos+"px"
    });
});
$(window).resize(function(){
    $(".px_bg_holder").css({
        "height" : $(window).height(),
        "width" : $(window).width()
    });
});
Rosmarine Popcorn
  • 10,761
  • 11
  • 59
  • 89
0

Not sure about other people, but this worked for me:

Z-index: -1

adrianmcli
  • 1,956
  • 3
  • 21
  • 49
0

With chrome 42, background attachment was not working for me... until I close Dev Tools.

Hope this can save someone's time!

Hugo H
  • 6,029
  • 5
  • 37
  • 57
0

bootstrap carousel was causing it for me. Adding this CSS to reverse transition properties fixed it.

#carouselName .carousel-inner div.item.active {
  /* left: 0; */
  -webkit-transform: none;
  transform: none;
  -webkit-backface-visibility: visible;
  -webkit-font-smoothing: antialiased;
  -webkit-perspective: none;
  -webkit-transform: none;
  -webkit-transition-delay: none;
  -webkit-transition-duration: none;
  -webkit-transition-property: none;
  -webkit-transition-timing-function: none;
  backface-visibility: visible;
}
D-bone
  • 1
0

If transform: translate3d(); is used anywhere on your website, background-attachment: fixed; will break in chrome. If possible, change all instances of transform: translate3d(); to transform: translate();. This should fix your problem.

Wilhelm
  • 1,407
  • 5
  • 16
  • 32