Bug Tracker

Opened 12 years ago

Closed 12 years ago

Last modified 11 years ago

#9880 closed bug (worksforme)

.css('background-position') returns inaccurate values in Chrome

Reported by: [email protected] Owned by:
Priority: low Milestone: None
Component: css Version: 1.6.2
Keywords: Cc:
Blocked by: Blocking:


This only is a problem for me in Chromium (version: 12.0.742.112 (90304) Ubuntu 11.04), things work fine in Firefox.

If I have this html:

<div id="test" style="background-position: 100px 100px;"></div>

The function:

function backgroundPosition () {
  return $('#test').css('background-position');

returns "120px 120px".

All pixel values seem like they're being multiplied by 120%, so any value greater than 4 is inaccurate (i.e. 5px will return 6px).

There's no problem with percentage values. The problem is the same even if I try to access background-position-x and background-position-y individually, pixel values are multiplied by 120%.

Here's a workaround I'm using that returns the correct value:

function backgroundPosition () {
  var container = $("<div></div>");

  return $(container.html()).css('background-position');

Change History (4)

comment:1 Changed 12 years ago by addyosmani

Component: unfiledcss
Priority: undecidedlow
Resolution: worksforme
Status: newclosed

Thanks for submitting a ticket!. I've put together a test case based on the information you've provided here: http://jsfiddle.net/addyosmani/WH7dz/. Using jQuery (edge/git) ie. 1.6.2+ in Chromium 12.07, there is no different between the expected output in Firefox 5, Chrome and Chromium (ie. 100px). As such we'll be closing this ticket as worksforme, however if you are able to provide further information that another member of the team can verify as being an issue with core, we'll be happy to re-investigate.

comment:2 Changed 11 years ago by [email protected]

Hey there, I just ran into this issue, the background position is being multiplied by the level of zoom on the browser..

comment:3 Changed 11 years ago by dandormont

I am able to reproduce this using the following JSFiddle:


It prints 83px 83px instead of 100px 100px. Using the plain DOM API produces the correct value.

This is reproducible in Google Chrome version 16.0.912.63 on Mac OS 10.6 with a Zoom level set to one below the default (in other words, if you hit Zoom Out once).

comment:4 Changed 11 years ago by anonymous

I have found this problem too. Is there any temporary fix available?

Note: See TracTickets for help on using tickets.