468,170 Members | 1,918 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,170 developers. It's quick & easy.

position:absolute relative to parent or to window?

Hello,

as I understand the specs http://www.w3.org/TR/CSS21/visuren.html#x19 an
absolute positioned block element is positioned relative to its parent
element. This is told in the german selfhtml reference, too:
http://de.selfhtml.org/navigation/cs...positionierung

In fact firefox and konqueror do position the block relativ to the window
border. This is explained here, too:
http://www.w3schools.com/dhtml/dhtml_css.asp

Which behaviour is correct?

Here is an example:

<html>
<head>
<style type="text/css">
#header { height: 44px;
border: 1px solid black;}

#copyright { border: 1px solid green;
position: absolute;
right: 12px;
bottom: 0px; }

</style>
</head>

<body>
<div id="header">
<div id="copyright">
blah foo text
</div>
</div>
</body>
</html>

--
Jul 27 '05 #1
6 18533
Gert Brinkmann wrote:
as I understand the specs http://www.w3.org/TR/CSS21/visuren.html#x19 an
absolute positioned block element is positioned relative to its parent
element.
No, to its containing block, which is defined as the nearest ancestor
element which has a position property with a value other than "static". If
there is no such element then it is from the edges of the viewport.
In fact firefox and konqueror do position the block relativ to the window
border.
Only if there isn't a containing block ... and you don't have any toolbars
or menu bars in your window.
This is explained here, too:
http://www.w3schools.com/dhtml/dhtml_css.asp


W3Schools - wrong again.

--
David Dorward <http://blog.dorward.me.uk/> <http://dorward.me.uk/>
Home is where the ~/.bashrc is
Jul 27 '05 #2
David Dorward wrote:
Gert Brinkmann wrote:
as I understand the specs http://www.w3.org/TR/CSS21/visuren.html#x19 an
absolute positioned block element is positioned relative to its parent
element.


No, to its containing block, which is defined as the nearest ancestor
element which has a position property with a value other than "static". If
there is no such element then it is from the edges of the viewport.


Thank you very much for your answer. It's unbelievable, but it is true. This
is the way, firefox behaves (I did not check other browsers). Hmm, does
this behaviour make sense? But ok, this is not the question here.

Thanks again,

Gert

Jul 28 '05 #3
>>
No, to its containing block, which is defined as the nearest ancestor
element which has a position property with a value other than "static". If
there is no such element then it is from the edges of the viewport.


Thank you very much for your answer. It's unbelievable, but it is true. [...]

Why is it unbelievable? It provides a way to position:absolute in any
containing block.

--
jmm dash list (at) sohnen-moe (dot) com
(Remove .AXSPAMGN for email)
Jul 28 '05 #4
Jim Moe wrote:
Why is it unbelievable? It provides a way to position:absolute in any
containing block.


Certainly yes, but IMHO it is not very intuitive. If you lay out a DIV
containing a lot of styled HTML, I do not like that the content changes
layout if you change the placing of the DIV. But perhaps I first have to
internalise(?) this technique.

Gert

Jul 29 '05 #5
Gert Brinkmann wrote :
David Dorward wrote:

Gert Brinkmann wrote:

as I understand the specs http://www.w3.org/TR/CSS21/visuren.html#x19 an
absolute positioned block element is positioned relative to its parent
element.


No, to its containing block, which is defined as the nearest ancestor
element which has a position property with a value other than "static". If
there is no such element then it is from the edges of the viewport.

Thank you very much for your answer. It's unbelievable, but it is true. This
is the way, firefox behaves (I did not check other browsers). Hmm, does
this behaviour make sense? But ok, this is not the question here.

Thanks again,

Gert


I personally reported this bug at Opera some 30 months ago when Opera
7.0 beta 1 came out. I also reported the problem, that precise bug to
MSIE 7 dev. team too.

"percentage width value on absolutely positioned elements should
calculate the %tage of the containing block, not %tage of the immediate
parent node of the abs. pos. elements. Safari 1.x and Mozilla-based
browsers supports this correctly (...)"
http://channel9.msdn.com/wiki/defaul...rSupportforCSS

FYI, Opera 6.06 did not have that bug: it was positioning an abs. pos.
element regarding its positioned ancestor otherwise relative to the
viewport dimension.

Gérard
--
remove blah to email me
Jul 29 '05 #6
Gert Brinkmann wrote:
Jim Moe wrote:
Why is it unbelievable? It provides a way to position:absolute in any
containing block.


Certainly yes, but IMHO it is not very intuitive. If you lay out a DIV
containing a lot of styled HTML, I do not like that the content changes
layout if you change the placing of the DIV. But perhaps I first have to
internalise(?) this technique.


See it this way:

If you have

<div class="a">
..
<div class="b">..</div>
..
</div>

and div.b should be positioned relative to div.a, you don't want the layout
to change, if you insert (for semantic reasons) another level inbetween:

<div class="a">
..
<div>
<div class="b">..</div>
</div>
..
</div>

--
Benjamin Niemann
Email: pink at odahoda dot de
WWW: http://www.odahoda.de/
Jul 29 '05 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Alexander Fischer | last post: by
3 posts views Thread by Markus Ernst | last post: by
4 posts views Thread by Peter Pfannenschmid | last post: by
6 posts views Thread by alex | last post: by
1 post views Thread by gcdp | last post: by
reply views Thread by kamranasdasdas | last post: by
reply views Thread by gcreed | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.