Determine dynamically how far from the left of the Client area an element is?

G

George Hester

Say I have this in a web page:

<center><a href="http://www.microsoft.com">www.microsoft.com</a></center>

I can use CSS, the DOM and\or JavaScript to determine the width style.innerHTML.length of the www.micosoft.com. But how can I tell in pixels how far it is from the left side of the client area using JavaScript? If the browser is resized and the text wraps the distance will change. So I need to determine it dynamically. Thanks.
 
T

Thomas 'PointedEars' Lahn

George said:

Do not use the `center' element, it is deprecated. Use the
`p' or `div' element and CSS' `text-align:center' instead.
I can use CSS, the DOM and\or JavaScript to determine the width
style.innerHTML.length of the www.micosoft.com. But how can I tell
in pixels how far it is from the left side of the client area using
JavaScript?

Use the DOM either. IE provides the `offsetLeft' property
while with standards-compliant UAs like Mozilla you can use
the getComputedStyle(...) method. Questions like this were
asked a few times, especially in the last days. Please
search/read *before* you post.
If the browser is resized and the text wraps the distance will change.

What's the problem?
So I need to determine it dynamically.

You only need working markup. What if JavaScript is disabled or not
supported? What if the DOM of the UA does not allow for reading the
computed coordinates? (X)HTML is not designed to be a layout language
or format like PDF. That the text flow adjusts automatically to the
client area instead of scaling the content to its size is its major
advantages, and you cannot fix design flaws in Web documents with
JavaScript reliably.


PointedEars
 
G

George Hester

Thomas unfortunately I can only use what I have. When I made the site I used <center>. Yes I know I shouldn't have but now that I have that is what I have. And if I can work around that with an idea that would be much easier then going through the site which is pretty large and changing all the center tags. That would be a lot of work. See that is why we aren't suppose to use it. I know. But I have and that is what I have.

Well I hope in your following text you have a suggestion on how to do what I want to do. Because that basically is what I am asking. I don't care if some browsers cannot support it. I don't care if it follows the rules. I don't care about anything else other then a suggestion how to do what I asked to do. If the answer is "you cannot" with what I have provided then that is fine. Say so.
 
T

Thomas 'PointedEars' Lahn

What did I do wrong to deserve such a posting?

George said:
Thomas unfortunately I can only use what I have. When I made the
site I used <center>. Yes I know I shouldn't have but now that I
have that is what I have.

So bad design in the past justifies bad design in the future?
And if I can work around that with an idea that would be much easier
then going through the site which is pretty large and changing all
the center tags. That would be a lot of work.

Sure it will but it will pay off. You can take that literally if you
run a commercial web site.
See that is why we aren't suppose to use it. I know. But I have and
that is what I have.

See above.
Well I hope in your following text you have a suggestion on how to do
what I want to do.

I already did.
Because that basically is what I am asking. I don't care if some
browsers cannot support it. I don't care if it follows the rules.

So if you do not care for your visitors, what the heck do you then want
on the Web -- posing yourselves? I will not support you in doing that.
Go away, now.


PointedEars
 
G

George Hester

Thomas you gave the answer offsetLeft. That did what I wanted. If you had posted "offsetLeft" and nothing else you would have provided what I asked for. But you chose to provide an opinion on what I wanted to do pointing out where I was wrong for asking what I asked. I'll go away and I hope you do too. I do not need this crap.
 

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,755
Messages
2,569,537
Members
45,023
Latest member
websitedesig25

Latest Threads

Top