S
Stevo
I have a DIV that's inside another DIV, I'll call them inner and outer.
To find the X (left) position on the page of the inner DIV, I do the
standard method of accumulating the offsetLeft values while chaining up
the offsetParent hierarchy until I reach the top (offsetParent==null).
If the outer DIV has no border/margin/padding CSS, then this usually
works just fine.
If however the outer DIV has border set by CSS, then my position
calculation function is off by that many pixels. I wanted to try and
compensate for this by adding the value of the border (or margin or
padding) of the outer DIV but when I interrogate any of the inner DIv's
..style.border properties, I get an empty string back.
I've interrogated all of the properties inside .style in Visual Studio,
and none of them held the "3px" that I was looking for. The only place I
could find them, was in the alternate .currentStyle. The border
properties in there do present me with my elusive "3px". So I could
fashion a solution for IE like this:
document.getElementById("outerdiv").currentStyle.borderWidth
Whenever I would want to get the position of innerDiv, I call my
position function and add the pixels found in this currentStyle
property. It's non-standard and IE only and therefore not much use to
me. It's also hacky.
Even if I wanted to have a branch to test if currentStyle exists, there
is no equivalent property in Gecko browsers for my else statement. I see
in Firebug (in Firefox) that it has only .style and again all the border
values are "". There are a lot of special Moz properties but none of
them have the border value I'm looking for.
I'm sure I can't be the only person suffering from this. So far I've
never found that I've needed to worry about border/margin/padding
because 99.9% of the outerdiv's that my innerdiv might find itself
inside, have had no such values to worry about.
Here's the CSS that was applied to the outer DIV:
#outer {
border:3px solid #2B5E88;
height:400px;
left:262px;
position:absolute;
top:440px;
width:400px;
}
My position function returns the same value for inner as for outer, even
though the inner DIV is 3 pixels down and right compared to outer.
To find the X (left) position on the page of the inner DIV, I do the
standard method of accumulating the offsetLeft values while chaining up
the offsetParent hierarchy until I reach the top (offsetParent==null).
If the outer DIV has no border/margin/padding CSS, then this usually
works just fine.
If however the outer DIV has border set by CSS, then my position
calculation function is off by that many pixels. I wanted to try and
compensate for this by adding the value of the border (or margin or
padding) of the outer DIV but when I interrogate any of the inner DIv's
..style.border properties, I get an empty string back.
I've interrogated all of the properties inside .style in Visual Studio,
and none of them held the "3px" that I was looking for. The only place I
could find them, was in the alternate .currentStyle. The border
properties in there do present me with my elusive "3px". So I could
fashion a solution for IE like this:
document.getElementById("outerdiv").currentStyle.borderWidth
Whenever I would want to get the position of innerDiv, I call my
position function and add the pixels found in this currentStyle
property. It's non-standard and IE only and therefore not much use to
me. It's also hacky.
Even if I wanted to have a branch to test if currentStyle exists, there
is no equivalent property in Gecko browsers for my else statement. I see
in Firebug (in Firefox) that it has only .style and again all the border
values are "". There are a lot of special Moz properties but none of
them have the border value I'm looking for.
I'm sure I can't be the only person suffering from this. So far I've
never found that I've needed to worry about border/margin/padding
because 99.9% of the outerdiv's that my innerdiv might find itself
inside, have had no such values to worry about.
Here's the CSS that was applied to the outer DIV:
#outer {
border:3px solid #2B5E88;
height:400px;
left:262px;
position:absolute;
top:440px;
width:400px;
}
My position function returns the same value for inner as for outer, even
though the inner DIV is 3 pixels down and right compared to outer.