Closed
Bug 129375
Opened 22 years ago
Closed 20 years ago
absolutely position div within another absolutely positioned div has a zero offsetWidth property
Categories
(Core :: Layout: Positioned, defect, P3)
Tracking
()
RESOLVED
FIXED
Future
People
(Reporter: doug_anderson, Assigned: MatsPalmgren_bugz)
References
Details
(Keywords: testcase)
Attachments
(2 files, 1 obsolete file)
From Bugzilla Helper:
User-Agent: Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)
BuildID: Gecko/20020204
<html>
<head>
<title>NS6 offsetWidth Bug</title>
<script>
<!--
function Init()
{
var div0 = document.getElementById("div0");
var div1 = document.getElementById("div1");
var div2 = document.getElementById("div2");
alert("div0.offsetWidth=" + div0.offsetWidth + " \n(a single positioned
<div> is non-zero as expected)");
alert("div1.offsetWidth=" + div1.offsetWidth + " \n(a position <div>
within another positioned <div> should not have zero width)");
alert("div1.offsetHeight=" + div1.offsetHeight + " \n(a position <div>
within another positioned <div> returns a valid offsetHeight)");
alert("div2.offsetWidth=" + div2.offsetWidth + " \n(a third non-
positioned <div> fixes the problem)");
}
//-->
</script>
<style>
.absS { position: absolute; left: 0px; top: 0px; }
#discussion { position: absolute; left: 10px; top: 120px; font-family:
sans-serif; }
</style>
</head>
<body bgcolor="#ffffff" onLoad="Init()">
<div id="div0" class="absS">A simple div within a div</div>
<div class="absS" style="top: 40px"><div id="div1" class="absS">A second div
within a div</div></div>
<div class="absS" style="top: 80px"><div class="absS"><div id="div2">A third
div within a div</div></div></div>
<div id="discussion"
><b>Problem:</b><br>
If an absolutely positioned <div> is placed within another absolutely
positioned <div>,
the inner <div> always returns zero for the "offsetWidth" and
"scrollWidth" properties.
While the inner <div> should be taken out of the flow and not contribute
to the outer <div>'s size,
the inner <div> itself should still have a height and width. It might be
worth noting that the
vertical counterparts "offsetHeight" and "scrollHeight" do
correctly return valid
values on the inner <div></div>
</body>
</html>
Reproducible: Always
Steps to Reproduce:
1.Run the example included in the description
2.
3.
Updated•22 years ago
|
Component: Browser-General → Layout
Summary: An absolutely position div within another absolutely positioned div has a zero offsetWidth property → absolutely position div within another absolutely positioned div has a zero offsetWidth property
Comment 1•22 years ago
|
||
Comment 2•22 years ago
|
||
Attachment #89715 -
Attachment is obsolete: true
Comment 4•22 years ago
|
||
Confirming in 2002-07-12-08 build.
Status: UNCONFIRMED → NEW
Ever confirmed: true
Priority: -- → P3
Updated•22 years ago
|
Target Milestone: --- → Future
Comment 5•21 years ago
|
||
-> David Baron
Assignee: attinasi → dbaron
Component: Layout → Layout: R & A Pos
Depends on: 170927
QA Contact: petersen → ian
Comment 6•20 years ago
|
||
*** Bug 242682 has been marked as a duplicate of this bug. ***
Workaround. I used it for a popup menu but it can be set for other tags too. /* workaround for mozilla bug #129375 we move the object to the body node, get the offsetWidth and set the width manually. then we move it back to the origin node */ function fixWidth (o) { while (o) { if (o.firstChild) fixWidth(o.firstChild); if (o.nodeType==1&&o.tagName.toLowerCase()=='ul') fixNow(o); o=o.nextSibling; } } function fixNow(o) { if (o.style.width&&o.style.width.length!=0) return; var op=o.parentNode; var next=o.nextSibling; o.ownerDocument.body.appendChild(o); o.style.position='absolute'; o.style.width=o.offsetWidth; if(next) op.insertBefore(o,next); else op.appendChild(o); }
Comment 8•20 years ago
|
||
This bug also causes borders to display incorectly.
Comment 9•20 years ago
|
||
Sorry if this is a dump question. I'm new to the Mozilla code. Which method dose this calculation? nsGenericHTMLElement::GetOffsetWidth or nsComputedDOMStyle::GetOffsetWidthFor
Keywords: helpwanted
Assignee | ||
Updated•20 years ago
|
Assignee | ||
Comment 10•20 years ago
|
||
I now get 46 (52 for the border case) for the DIV that previously returned 0. -> FIXED (by bug 201897)
You need to log in
before you can comment on or make changes to this bug.
Description
•