Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Get an elements specified style

1 view
Skip to first unread message

Steven Roussey

unread,
Dec 3, 2009, 4:18:03 PM12/3/09
to
In the following document, I have an absolutely positioned element
with id of "b" that was positioned from the right. How can I tell how
it was positioned? If I get the computedStyle I get both left and
right with no knowledge of which one is fixed (that is, if I resize
the window, the value of right will stay the same, the value of left
will change). The only way I can think of is to iterate through all
the styles that apply to this object from getCSSStyleRules() to find
what the collapsed specified style is. Is this correct? Is there a
shorter/faster way to find the specified style?

<!DOCTYPE HTML>
<html>
<body>
<style type="text/css">
#d {
height:300px;
position: relative;
background: yellow
}
#a {
position: relative;
bottom: 5px
}
#b {
position: absolute;
bottom: 250px;
right: 10px
}
</style>
<div id="d">
<img id="a" src="http://www.google.com/images/firefox/amo.png">
<img id="b" src="http://www.google.com/images/firefox/amo.png">
</div>
</body>
</html>

Boris Zbarsky

unread,
Dec 3, 2009, 4:36:10 PM12/3/09
to
On 12/3/09 4:18 PM, Steven Roussey wrote:
> In the following document, I have an absolutely positioned element
> with id of "b" that was positioned from the right. How can I tell how
> it was positioned?

You examine its rules and see which ones are relevant?

> The only way I can think of is to iterate through all
> the styles that apply to this object from getCSSStyleRules() to find
> what the collapsed specified style is.

At the moment, yes.

> Is there a shorter/faster way to find the specified style?

No, but there have been repeated requests for one. It wouldn't actually
be that hard to do, I think.... And we definitely have a bug on it.
Helpwanted.

-Boris

0 new messages