Opera Bug #DSK-246965

Offset values for elements within the <body> return offset values from the <html> element

Affects up to Opera 11.10

In all HTML documents, the <html> element is the root element, or documentElement. The <body> element is contained inside the <html> element and is considered the final offsetParent. Opera correctly returns null when asked for the document.body.offsetParent.

Normally, the offset edges of the <html> and <body> elements overlap precisely. This is the default behaviour which few authors feel the need to change, so offsets are reported as expected.

However it is possible to give margins to the <body> element so that its edges are pulled in from the edges of the <html> element. If the <body> element is then given the CSS style position:relative; it should become the offsetParent for all child nodes in the document. In this situation, child elements of the <body> element misreport their offsetLeft and offsetTop in Opera. Opera reports the offsetLeft and offsetTop relative to the <html> element rather than its reported offsetParent, the BODY node.

The <body> element of this document has been given a margin of 40px all around. The <html> element is the white border you can see around the edges of the document. Because the <body> element has a padding of 10px, the left and top edges of the bordered element at the top left of this document are 50px away from the very edge of the viewport, but only 10px from the edges of its offsetParent.

Main Bug List