W3C and style.left question

I

ivanhoe

What I wanted was to get rid of offsetLeft and use "proper" way
instead....but when I do
document.getElementById('someDiv').style.left;
I keep getting empty string, unless I first set it manually (in CSS or js)
to some value...

if that is intended behavior(that is if I haven't f***d up something :) in
my code), and there is no offsetLeft property in W3C recommendation, what is
then "standard compliant" way to make browser calculate coordinates of some
tag on the page???

thanx in advance,
ivan
 
M

Martin Honnen

ivanhoe said:
What I wanted was to get rid of offsetLeft and use "proper" way
instead....but when I do
document.getElementById('someDiv').style.left;
I keep getting empty string, unless I first set it manually (in CSS or js)
to some value...

if that is intended behavior(that is if I haven't f***d up something :) in
my code), and there is no offsetLeft property in W3C recommendation, what is
then "standard compliant" way to make browser calculate coordinates of some
tag on the page???

If you don't set the CSS inline style with CSS (e.g
<tag style="left: 100px;">
) or with script (e.g
elementObject.style.left = '100px';
) then it is correct that element.style.left returns an empty string as
element.style.cssProperty is not a cascaded computed CSS value but
simply a reflection of the inline style set on an element.
If you want a computed CSS value then with Netscape 6/7, Mozilla and
with Opera 7 you have DOM Level 2 support for
window.getComputedStyle(element, '').getPropertyValue('left')
however what browsers implement as offsetLeft follows different rules
compared to what getComputedStyle does so if your application works well
across browsers reading offsetLeft on abritrary elements you should in
my view stick with that. Or if you want to use getComputedStyle make
sure you test for your elements whether there are differences to
offsetLeft and adapt your script expressions if needed.
 
D

DU

ivanhoe said:
What I wanted was to get rid of offsetLeft and use "proper" way
instead....but when I do
document.getElementById('someDiv').style.left;
I keep getting empty string, unless I first set it manually (in CSS or js)
to some value...

The css position property value defaults to static; it must be set to
relative or absolute or fixed, otherwise setting
ElemRef.style.left
to some value does not make any sense.
if that is intended behavior(that is if I haven't f***d up something :) in
my code), and there is no offsetLeft property in W3C recommendation,

True, there is no offsetLeft property in W3C recommendation. I think W3C
should have adopted the MSIE's DHTML object model. offset* values are
often very useful.

what is
then "standard compliant" way to make browser calculate coordinates of some
tag on the page???

thanx in advance,
ivan

The coordinates you're referring to must be relative to some point of
reference. offset* values are relative to offsetParent element: that's
per definition. offsetParent is not part of the DOM Core. left, top,
bottom, right css properties (for abs. pos. elements) are relative to
the closest containing positioned element within the containment
hierarchy. There is a sharp distinction between the 2.

Interactive demo page on CSS positioning
http://www10.brinkster.com/doctorunclear/HTMLJavascriptCSS/Positioning.html

DU
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,170
Latest member
Andrew1609
Top