background-position-y doesn't work in Firefox (via CSS)?

HtmlCssFirefox

Html Problem Overview


In my code the background-position-y doesn't work. In Chrome it's ok, but not working in Firefox.

Anyone have any solution?

Html Solutions


Solution 1 - Html

If your position-x is 0, there's no other solution than writing :

background-position: 0 100px;

background-position-x is a non-standard implementation coming from IE. Chrome did copy it, but sadly not firefox...

However this solution may not be perfect if you have separate sprites on a big background, with rows and cols meaning different things... (for example different logos on each row, selected/hovered on right, plain on left) In that case, I'd suggest to separate the big picture in separate images, or write the different combinations in the CSS... Depending on the number of sprites, one or the other could be the best choice.

Solution 2 - Html

Use this

background: url("path-to-url.png") 89px 78px no-repeat;

Instead of this

background-image: url("path");
background-position-x: 89px;
background-position-y: 78px;
background-repeat: no-repeat;

Solution 3 - Html

> background-position-y :10px; is not working in Firefox web browser.

You should follow this type of syntax:

background-position: 10px 15px;

10px is bounded to "position-x" and 15px bounded to "position-y"

100% working Solution

Follow this URL for more examples

Solution 4 - Html

Firefox 49 will be released—with support for background-position-[xy]—in September 2016. For older versions up to 31, you can use CSS variables to achieve positioning the background on a single axis similar to using background-position-x or background-position-y. CSS variables reached Candidate Recommendation status in December 2015.

The following is a fully cross-browser example of modifying background position axes for sprite images on hover:

:root {
    --bgX: 0px;
    --bgY: 0px;
}

a {
    background-position: 0px 0px;
    background-position: var(--bgX) var(--bgY);
}

a:hover, a:focus { background-position-x: -54px; --bgX: -54px; }
a:active   { background-position-x: -108px; --bgX: -108px; }
a.facebook { background-position-y: -20px; --bgY: -20px;  }
a.gplus    { background-position-y: -40px; --bgY: -40px;  }

Solution 5 - Html

background: url("path") 89px 78px no-repeat;

Will not work if you want a background along with the image. So use:

background: orange url("path-to-image.png") 89px 78px no-repeat;

Solution 6 - Html

Why don't you use background-position directly?

Use:

background-position : 40% 56%;

Instead Of:

background-position-x : 40%;
background-position-y : 56%

Solution 7 - Html

This worked for me:

a {
    background-image: url(/image.jpg);
    width: 228px;
    height: 78px;
    display: inline-block;
}

a:hover {
    background-position: 0 -78px;
    background-repeat: no-repeat;
}

Solution 8 - Html

>However this solution may not be perfect if you have separate sprites on a big background, with rows and cols meaning different things... (for example different logos on each row, selected/hovered on right, plain on left) In that case, I'd suggest to separate the big picture in separate images, or write the different combinations in the CSS... Depending on the number of sprites, one or the other could be the best choice.

Mine has the exact problem as stated by Orabîg which has a table like sprite which has columns and rows.

Below is what I used as a workaround using js

firefoxFixBackgroundposition:function(){
  $('.circle').on({
    mouseenter: function(){
       $(this).css('background-position',$(this).css('background-position').split(' ')[0]+' -10px');   
    },
    mouseleave: function(){
       $(this).css('background-position',$(this).css('background-position').split(' ')[0]+' 0');   
    }
  });      
}

Solution 9 - Html

Make certain you explicitly state the measurement of your offset. I came across this exact issue today, and it was due to how browsers interpret the values you provide in your CSS.

For example, this works perfectly in Chrome:

background: url("my-image.png") 100 100 no-repeat;

But, for Firefox and IE, you need to write:

background: url("my-image.png") 100px 100px no-repeat;

Hope this helps.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionMarlos CarmoView Question on Stackoverflow
Solution 1 - HtmlOrabîgView Answer on Stackoverflow
Solution 2 - Htmlfarshad saeidiView Answer on Stackoverflow
Solution 3 - HtmlEashanView Answer on Stackoverflow
Solution 4 - HtmlAndy EView Answer on Stackoverflow
Solution 5 - HtmlPiotr ŚródkaView Answer on Stackoverflow
Solution 6 - HtmlSandeep GantaitView Answer on Stackoverflow
Solution 7 - HtmlStefanView Answer on Stackoverflow
Solution 8 - Htmlace.spadesView Answer on Stackoverflow
Solution 9 - HtmlMike ZavarelloView Answer on Stackoverflow