Open mstensho opened 6 years ago
Is this essentially the same as #576, just the float-preceding case rather than the float-subsequent case?
I don't think so. Please note that the examples that were meant to be part of the initial comment here were invisible, because I had forgotten a few backticks. Fixed now. The floats in my examples have non-zero height, which is an important detail (which was impossible to deduce from the text alone).
To be fair, I did look very quickly through all the open CSS2 issues and didn't think about them much. :)
As I see it, it's still possible to overlap a float even if it has an area of 0. Along the same lines, #5641 said that boxes with an area of 0 can intersect the viewport.
It's worth noting that there are some browser differences depending on which dimension is 0:
<!DOCTYPE html>
<div style="margin-left:50px; width:100px;">
<div style="float:left; width:0px; height:50px; outline:solid red"></div>
<div style="float:right; width:0px; height:50px; outline:solid red;"></div>
<div style="float:left; clear:both; width:25px; height:0px; outline:solid green"></div>
<div style="float:right; clear:both; width:25px; height:0px; outline:solid green;"></div>
<div style="float:left; width:0px; height:50px; outline:solid blue"></div>
<div style="float:right; width:0px; height:50px; outline:solid blue;"></div>
<div style="overflow:hidden; width:200px; margin:0 -50px; height:150px; background:cyan;"></div>
</div>
Gecko, WebKit | Blink | Spec |
---|---|---|
Another testcase:
<!DOCTYPE html>
<div style="overflow: hidden; width:50px; border: solid; margin: 10px">
<div style="float:left; clear:left; width:25px; height:10px; background:magenta"></div>
<div style="float:left; width:0px; height:25px; outline:solid orange"></div>
<div style="overflow:hidden; width:40px; height:50px; background:cyan;"></div>
</div>
<div style="overflow: hidden; width:50px; border: solid; margin: 10px">
<div style="float:left; width:10px; height:25px; background:magenta"></div>
<div style="float:left; clear:left; width:25px; height:0px; outline:solid orange"></div>
<div style="overflow:hidden; width:40px; height:50px; background:cyan;"></div>
</div>
Gecko | WebKit | Blink | Servo | Servo+patch |
---|---|---|---|---|
I was actually interpreting the spec to mean "Servo+patch", and I have written a patch for Servo to implement that. But then I noticed this in https://drafts.csswg.org/css2/#floats
A line box is next to a float when there exists a vertical position that satisfies all of these four conditions: (a) at or below the top of the line box, (b) at or above the bottom of the line box, (c) below the top margin edge of the float, and (d) above the bottom margin edge of the float. Note: this means that floats with zero outer height or negative outer height do not shorten line boxes.
Effectively, both Blink and Servo+patch are then wrong here:
<!DOCTYPE html>
<div style="float: left; width: 10px; height: 10px; background: cyan"></div>
<div style="float: left; clear: left; width: 100px; outline: solid magenta"></div>
lorem ipsum
Gecko / WebKit / Servo | Blink / Servo+patch |
---|---|
I'm not convinced it makes sense for independent formatting contexts to avoid 0px tall floats if text shouldn't avoid them.
And then it could be said that 0px wide floats shouldn't be avoided either for consistency? That said, consider
<!DOCTYPE html>
<div style="width: 50px">
<div style="float: left; width: 25px; height: 1px; background: cyan"></div>
<div style="float: left; height: 100px; outline: solid magenta"></div>
loremipsum
</div>
Gecko / WebKit / Blink | Servo / Servo+patch |
---|---|
By the above definition in CSS2, the line box is next to the magenta float, so it should shrink to avoid it, and then the text doesn't fit, so
If a shortened line box is too small to contain any content, then the line box is shifted downward (and its width recomputed) until either some content fits or there are no more floats present.
It seems to me that Gecko / WebKit / Blink aren't following this.
Summary table:
Avoids: | 0px wide floats for independent FC |
0px wide floats for text |
0px tall floats for independent FC |
0px tall floats for text |
---|---|---|---|---|
Gecko | ❌ | ❌ | ❌ | ❌ |
WebKit | Sometimes | ❌ | ❌ | ❌ |
Blink | ❌ | ❌ | ✅ | ✅ |
Servo | ✅ | ✅ | ❌ | ❌ |
Servo+patch | ✅ | ✅ | ✅ | ✅ |
The CSS Working Group just discussed [CSS2] How do zero-width floats affect subsequent content
.
https://www.w3.org/TR/CSS22/visuren.html#float-position doesn't seem to mention anything particular about zero-width floats. Should a zero-width margin box be considered to be a margin box at all?
Chrome, Edge and Firefox all show a green square here. The relevant spec wording:
"The border box of a table, a block-level replaced element, or an element in the normal flow that establishes a new block formatting context (such as an element with 'overflow' other than 'visible') must not overlap the margin box of any floats in the same block formatting context [...]"
So a zero width float has no outer/margin box at all?
At the same time, all the browsers mentioned agree that zero-width floats should affect the block position of subsequent floats and blocks affected by clearance:
Here we get a green square above a lime square.