It is currently Sat Dec 02, 2017 4:10 pm Advanced search
<!doctype html>
<title>Margin collapsing and absolutely positioned elements</title>
<style>
p { margin-bottom:50px; width:10em; border-bottom:10em solid red; }
div { position:absolute; width:10em; height:10em; background:lime; margin-top:-10em; }
</style>
<p>There should be a green box below and no red:
<div></div>
Margins of absolutely positioned boxes do not collapse (not even with their in-flow children).
Two or more adjoining vertical margins of block boxes in the normal flow collapse. The resulting margin width is the maximum of the adjoining margin widths. In the case of negative margins, the maximum of the absolute values of the negative adjoining margins is deducted from the maximum of the positive adjoining margins. If there are no positive margins, the absolute maximum of the negative adjoining margins is deducted from zero.
If 'top' has the value 'auto' replace it with the distance from the top edge of the containing block to the top margin edge of a hypothetical box that would have been the first box of the element if its 'position' property had been 'static'. (But rather than actually computing that box, user agents are free to make a guess at its probable position.)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Boxes</title>
<style type='text/css'>
body
{
background: red;
margin: 50px;
/*border: 3px solid green;*/
}
#div1
{
position: absolute;
left: 100px;
top: 100px;
min-width: 400px;
padding: 0px;
background: white;
border: 2px solid brown ;
}
p
{
background: yellow;
margin: 0px;
margin-bottom: 50px;
}
#footer
{
position: absolute;
background: gray;
padding: 35px;
left: 10px;
right: 10px;
border: 1px solid yellow;
}
#box1
{
position: absolute;
left: 20px;
height: 20px;
width: 20px;
bottom: 0px;
background: green;
}
#box2
{
position: absolute;
width: 20px;
height: 20px;
right: 20px;
bottom: 0px;
background: lime;
}
</style>
<script type='text/javascript'>
window.onload = function ()
{
// IE does not implement createElementNS
//var newDiv = document.createElementNS("http://www.w3.org/1999/xhtml", "div");
var newDiv = document.createElement("div");
newDiv.id = "box1";
document.getElementById("div1").appendChild(newDiv);
newDiv = document.createElement("div");
newDiv.id = "box2";
document.getElementById("div1").appendChild(newDiv);
}
</script>
</head>
<body>
<div id='div1'>
This is an abolutely positioned <code>div</code> containg all the text and all the other elements.
<p>Normal paragraph in the flow with <code>margin-bottom: 50px;</code></p>
<div id='footer'>
- This absolutely positioned <code>div</code> is positioned differently in different browsers: Safari and IE7 respect the <code>margin-bottom</code> set on the preceding <code>p</code>; Opera and Firefox ignore it.
<br style="margin-after: 1em;">
- The light green square (created using <code>createElement()</code>) does not render correctly in Opera; the dark green (created using <code>createElementNS("http://www.w3.org/1999/xhtml",)</code>) does.
</div>
<div>static DIV which is nextSibling of 'footer'</div>
</div>
</body>
</html>
Test cases don't need to be conforming; they might test error handling for instance. However, in this case the test cases do in fact conform to the HTML5 syntax. All are not conforming HTML5 though, because div isn't allowed to have both block-level elements and inline-level content as children at the same time. But that doesn't affect what is being tested.MikeFoster wrote:I see several problems with your tests. First, I obviously don't understand something about HTML5 because IMO those files are completely invalid HTML.
MikeFoster wrote:IMO those files are completely invalid HTML.
MikeFoster wrote:rather than actually computing that box, user agents are free to make a guess at its probable position
MikeFoster wrote:Also note that my demo takes care of the Opera rendering issue.
http://html5.ouvaton.org/bugs3.html illustrates how borders collapse or not on static (green) and absolutely positioned (red) elements; there is a difference between IE7/Safari and Opera/Firefox, but where is the bug? In CSS 2.1?
...but I am not sure that your analysis actually explains why the problem occurred in the first place.
It was his file. He just changed the doctype.MikeFoster wrote:Yes, I know my file is valid HTML4.01. But I was refering to your files as invalid - however I was basing that on HTML4.01 - I am still quite ignorant on HTML5
I think you're misreading the spec. The guess-work is only a hint that UAs can optimize their implementation, but the end result still has to be the same as if they followed the algorithm literally.MikeFoster wrote:I don't think there is any bug at all. The CSS spec allows browsers to "guess" at what 'auto' means for an absolute element.
zcorpan wrote:It was his file. He just changed the doctype.
hasather wrote:Test 12 renders a blue rectangle for me in Opera 9.10 (build 521) on Linux.
Users browsing this forum: No registered users and 0 guests