p2p.wrox.com Forums

p2p.wrox.com Forums (http://p2p.wrox.com/index.php)
-   BOOK: Beginning CSS: Cascading Style Sheets for Web Design ISBN: 978-0-7645-7642-3 (http://p2p.wrox.com/forumdisplay.php?f=154)
-   -   chapter 11 figure 11-7 relative positioning (http://p2p.wrox.com/showthread.php?t=63957)

pelopito November 21st, 2007 07:55 AM

chapter 11 figure 11-7 relative positioning
 
hi, i have two questions:

a)when i apply a percentage value at the top
property of p#relative the p doesn't offset
from the top at all in Firefox but in IE6 it does.

any ideas why this is happening?

b)the percentage value for the top,bottom,right,left properties
is the percentage of the containing block's width or height.
in figure 11-7b if i put the p#relative into a div
and apply top:50%(or any other percentage value) in figure 11-7a, then the offset from top is calculated with respect to the height of the body not the height of the div(IE6).

any ideas why this is happening?

richard.york November 24th, 2007 06:31 PM

> when in figure 11-7a i apply a percentage value at the top
> property of p#relative the p#relative doesn#039;t offset
> from the top at all in Firefox but in IE6 it does.

Since I haven't had much need for the scenario you're describing, professionally speaking, I had to do some digging on the topic.

As stated in the book, the specifications state that an element with relative positioning should be rendered as part of the normal flow of a document. i.e., it should be placed where it would be were no positioning applied. Then relative positioning is applied relative to its original, static position. So the offset properties are applied relative to that position, rather than relative to the element's parent, except for percentage measurement, which is relative to the containing element.

http://www.w3.org/TR/CSS2/visuren.ht...ve-positioning
http://www.w3.org/TR/CSS2/visuren.html#propdef-top

"For relatively positioned boxes, the offsets are with respect to the outer edges of the box itself (i.e., the box is given a position in the normal flow, then offset from that position according to these properties"

"For 'top' and 'bottom', if the height of the containing block is not specified explicitly (i.e., it depends on content height), the percentage value is interpreted like 'auto'."

That second blurb explains what you're seeing, and that behavior occurs in Firefox, Safari, and Opera, they all agree. The height of the <body> element, which is the containing block in this example, is not explicitly defined. So, the top (or bottom) property with a percentage measurement is treated like "auto", or for all practical purposes, ignored. IE6 and IE7 are incorrect per the specification since they render the offset when the height is not explicitly defined. But you get the same outcome in IE6 and IE7 when you do specify an explicit height... you see the same rendering in IE as you do in Firefox, Opera, and Safari.

As to *why* the specification defines it that way, well, your guess is as good as mine. I'm sure someone, somewhere had a compelling reason for the limitation.

> the percentage value for the top,bottom,right,left properties
> is the percentage of the containing block#039;s width or height.
> in figure 11-7b if i put the p#relative into a div
> and apply top:50%(or any other percentage value) in figure 11-7a, then > the offset from top is calculated with respect to the height of the
> body not the height of the div(IE6).

If you add a CSS rule for the <div>, and within that the declaration, zoom: 1;, you get the expected result, percentage relative to the <div>. That's needed because this looks like an IE "hasLayout" bug. That topic is covered in my book, though I don't recall where. I didn't exhaustively cover the topic, but it is covered.

For more information see this link:
http://www.satzansatz.de/cssd/onhavinglayout.html

Hope this helps!

Regards,
Rich

--
Author,
Beginning CSS: Cascading Style Sheets For Web Design, 2nd Edition
CSS Instant Results

http://www.catb.org/~esr/faqs/smart-questions.html

pelopito November 29th, 2007 06:11 AM

Hi,
first of all i wanna thank you for the post
it helped me a lot!!

when i was experimenting with your suggestions
regarding question b) i found another solution
for the problem(besides zoom:1 that it worked just
fine in IE6,7). if i explicitly set the height for
the div then in IE6,7 the offset is calculated with
respect to the div.

regards,
Pelopito



All times are GMT -4. The time now is 08:58 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.