Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS: Safari Mobile doesn't support background-position offset

I have this property with multiple background images and their respective positions:

#my_div {
    background-image:url("..."), url("..."), url("...");
    background-position:right bottom, right bottom, right 15px top 17px;
}

The positioning for the third image works fine on FF, IE10, Chrome.. but unfortunately not on Safari Mobile. It renders the right and top thing but not the offsets (15px for right and 17px for top).. I couldn't find any reference on this. How would you deal with this? I'd avoid having to modify the image manually adding transparent borders to make the offset.

like image 355
MultiformeIngegno Avatar asked Jul 17 '26 13:07

MultiformeIngegno


1 Answers

Mobile Safari (as well as the Android browser) doesn't support the four-value syntax yet. (see the MDN article on background-position).

One possible workaround would be to extract the background image which should have the offset and put it in a pseudo element that has the corresponding offsets.

#my_div:before{
  content: '';
  display: block;
  position: absolute;
  z-index: -1;

  height: 50px; /* Height of your image / parent div */
  width: 50px; /* Width of your image / parent div */

  /* Your offset */
  top: 17px; 
  right: 15px;

  background-image: url("...");
  background-position: right top;
}

For easier understanding I created a jsFiddle: http://jsfiddle.net/pKWvp/1/

like image 156
Max Avatar answered Jul 20 '26 01:07

Max



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!