473,395 Members | 1,341 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

cell's offsetHeight not equal to cell's height?? firefox & IE

Tested in IE7 and FF2. I have 2 frames, 2 similar tables in them,
similar CSS. (I have 1px cellpadding, and 1px border aroud the cells.

From one frame I read the offsetHeight of a cell (getElementById), and
set the height of the corresponding cell in the other frame. Here:

window.parent.frames["lft"].document.getElementById('r2').style.height=(docum ent.getElementById('r2'i).offsetHeight)
+ 'px';

Everything works perfectly, cell gets resized, BUT then I read back
the height of both cells, here:

alert(document.getElementById('r2').offsetHeight + ' - ' +
window.parent.frames["lft"].document.getElementById('r2').offsetHeight );

In FireFox it returns 17 and 17 pixels, perfect. But IE7 returns 17
and 20 pixels (17 for the original cell, 20 for the newly resized
cell)! And they don't align! Why?

Why do the browsers act differently? And how could I compensate the
difference? Checking for IE and then substract 3 pixels doesn't feel
like a safe solution.

Any explanation or solution for this?
Aug 5 '08 #1
2 3976
On Aug 5, 4:01 pm, laszloke...@gmail.com wrote:
Tested in IE7 and FF2. I have 2 frames, 2 similar tables in them,
similar CSS. (I have 1px cellpadding, and 1px border aroud the cells.
You have cellpadding="1" or padding:1px?
>
From one frame I read the offsetHeight of a cell (getElementById), and
set the height of the corresponding cell in the other frame. Here:

window.parent.frames["lft"].document.getElementById('r2').style.height=(docum ent.getElementById('r2'i).offsetHeight)
+ 'px';
That assumes that the offsetHeight property is equal to the CSS
height. With the standard box model, this will not be true.
>
Everything works perfectly, cell gets resized, BUT then I read back
the height of both cells, here:

alert(document.getElementById('r2').offsetHeight + ' - ' +
window.parent.frames["lft"].document.getElementById('r2').offsetHeight );

In FireFox it returns 17 and 17 pixels, perfect. But IE7 returns 17
and 20 pixels (17 for the original cell, 20 for the newly resized
cell)! And they don't align! Why?
Just a guess, as you did not post any code or markup, but is one or
more of the pages rendered in quirks mode?
>
Why do the browsers act differently? And how could I compensate the
difference? Checking for IE and then substract 3 pixels doesn't feel
like a safe solution.
Good instinct.
>
Any explanation or solution for this?
Post the code.
Aug 5 '08 #2
la*********@gmail.com wrote:
Tested in IE7 and FF2. [...]
window.parent.frames["lft"].document.getElementById('r2').style.height=(docum ent.getElementById('r2'i).offsetHeight)
+ 'px';

Everything works perfectly, cell gets resized, BUT then I read back
the height of both cells, here:

alert(document.getElementById('r2').offsetHeight + ' - ' +
window.parent.frames["lft"].document.getElementById('r2').offsetHeight );

In FireFox it returns 17 and 17 pixels, perfect. But IE7 returns 17
and 20 pixels (17 for the original cell, 20 for the newly resized
cell)! And they don't align! Why?
The proprietary `offsetHeight' property value is not necessarily the same as
the CSS `height' property value. When you set the CSS `height' property on
the table cell in MSHTML, you define the client area height (not to be
confused with clientHeight). The 3 additional pixels account for the
padding around the client area and the borders around that. It can be
tested easily without a directly scripted assignment to the CSS property (IE
7.0.5730.11 CSS1Compat Mode, on WinXP SP3):

javascript:document.body.innerHTML = '<table><tr><td style="height:4px;
padding:2px; border:1px solid black;
line-height:0">&nbsp;</td></tr></table>');
window.alert(document.getElementsByTagName("td")[0].offsetHeight)

(Or you can create a static test case that only accesses offsetHeight.)

The alert window would shows 10 here, because

offsetHeight := height + padding + borders = 4 + 2*2 + 2*1 = 10.

(If line-height is not declared, it shows 22 for line-height:normal here; YMMV.)

See also <http://msdn.microsoft.com/en-us/library/ms530302(VS.85).aspx>.
Why do the browsers act differently?
Gecko implements the standards-compliant W3C CSS Box Model; IE implements
the proprietary MSHTML box model. Deprecated HTML formatting attributes and
BackCompat/Quirks Mode may also interfere.
And how could I compensate the difference?
Knowing what you are using, and computing it accordingly.
PointedEars
--
Prototype.js was written by people who don't know javascript for people
who don't know javascript. People who don't know javascript are not
the best source of advice on designing systems that use javascript.
-- Richard Cornford, cljs, <f8*******************@news.demon.co.uk>
Aug 5 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: joeZ | last post by:
hi there! I'm just going crazy with this stuff I want to do I though was simple. I just want to locate an image (which is linkeable) below the bottom of a cell. I mean, if the cell is at...
6
by: chris | last post by:
is there a way by using html or javascript or anything else for that matter to detirmine the actual height or width of a table or cell for example if i only set the height to 100 and the data in...
7
by: Andrew Poulos | last post by:
I'm using the following code to create a small table with one column and two rows. An image goes into the first cell. //create table var t = document.createElement("TABLE"); t.style.position =...
10
by: arkerpay2001 | last post by:
Layout Gurus, My program has divs that contain a single text node. I programatically set the myDiv.style.fontSize = "8pt"; When I call myDiv.offsetHeight, the number "14" is returned. Can...
4
by: Dacian | last post by:
Hi, I´m trying to place a javascript navigation menu inside a cell of a table in my page, the problem is that the constructor of the menu object has parameters for menu positioning and size and...
5
by: nivas.meda | last post by:
Hi, I have an excel sheet with a graph and cells.If i change the value in the excel cells the graph will reflect.Now i am going to implement this functionality in html page.I successfully saved...
1
by: Bart Lateur | last post by:
I'm trying to put a utton at the bottom (right) of a TD cell, irrespective of what else is in there. Usually, with other HTML block elements, we're told to use position: relative on the...
1
by: Manil | last post by:
I usually have no problem with Firefox, but here is a rare instance of IE displaying a table with image slices correctly and Firefox adding space where I seemingly have none. Is there anything I can...
1
by: bob2044 | last post by:
offsetHeight is not working in following code <script type="text/javascript"> function Coverdiv() { var standard=(document.compatMode=="CSS1Compat") ? document.documentElement:document.body;...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.