Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 144255
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T08:13:28+00:00 2026-05-11T08:13:28+00:00

I have some one page whose div elements are aligned by JavaScript. The JavaScript

  • 0

I have some one page whose div elements are aligned by JavaScript. The JavaScript just check a set of div elements to find the max offsetWidth, then set all div elements’ width to be the max offsetWidth. It works perfect in most browsers and locales, but it fails on french-France in Firefox on Mac. In this case, the content of div wraps.

<div id='divFoo'>     Heure de d&#233;but : </div> 

for above HTML, below code report ’79’.

javascript:alert(document.getElementById('divFoo').offsetWidth); 

but below code report ‘79.1333px’.

javascript:alert(window.getComputedStyle(document.getElementById('divFoo'),null).width)) 

The gap between 79.1333 and 79 makes incorrect width set to inline style.

I used to thought that offsetWidth and width should always be integer. Is there any way to make offsetWidth round correctly?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T08:13:29+00:00Added an answer on May 11, 2026 at 8:13 am

    There’s a difference between the CSS style rule (which getComputedStyle() or Renzo Kooi’s getStyle() will give you) and the actual computed width in pixels as determined by the user agent.

    This is partly due to the fact that partial pixel values are possible in CSS, but the user agent must choose how to render partial pixels (currently, I believe they all round up or down, but are very inconsistent, particularly when translating percents to pixels [see here]).

    It is important for these differences to exist, particularly as user agents implement full page zooming.

    For instance, I made a test case with this:

    <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN'     'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> <html xmlns='http://www.w3.org/1999/xhtml' xml:lang='en' lang='en'> <head>     <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>     <title>Fractional pixels</title>     <style type='text/css' media='screen'>         #fractional {             width: 17.5px;             height: 16.1333px;             background: red;         }     </style> </head> <body>     <div id='fractional'></div> </body> </html> 

    Zoomed in one step in Safari 4 Beta, the CSS width is reported as 17.5px and the height 16.1333px. But its offsetWidth is 21 device pixels, and its offsetHeight is 19 device pixels.

    The moral of the story, in short, is that if you want to match an element’s actual dimensions, it’s best to use its CSS values as is, even if they are non-integer.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 183k
  • Answers 183k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You can take a look at the params keyword: public… May 12, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer You might want to start looking through the chip documentation… May 12, 2026 at 4:41 pm
  • Editorial Team
    Editorial Team added an answer Workaround: os.getenv('PWD') May 12, 2026 at 4:41 pm

Related Questions

I'm doing some maintenance coding on a webapp and I am getting a javascript
I have a MasterPage that is two column layout, left column menu, right column
Is there a way to get struts 2 (using tiles) to build the whole
I am trying to build a page with the following in it: Already have

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.