summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/css/CSS2/floats/floats-wrap-bfc-with-margin-001a.tentative.html
blob: 9aa6b69ab7545a3a172d3d19d2ac4d6f0e52737b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
<!DOCTYPE html>
<html class="reftest-wait">
<meta charset="utf-8">
<title>CSS Test: If a BFC's inline-axis margin is sufficiently negative such
  that it inflates its border-box to be too large to fit alongside a float,
  then it should be pushed below the float</title>
<link rel="author" title="Daniel Holbert" href="mailto:dholbert@mozilla.com">
<link rel="help" href="https://www.w3.org/TR/CSS21/visuren.html#floats">
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#stretch-fit-sizing">
<meta name="assert" content="The border box of ... an element in the normal flow that establishes a new block formatting context ... must not overlap the margin box of any floats in the same block formatting context as the element itself. If necessary, implementations should clear the said element by placing it below any preceding floats">
<link rel="help" href="https://www.w3.org/TR/CSS21/visudet.html#blockwidth">
<!-- For a BFC with 'width:auto', negative total inline-axis margins will
     effectively set a lower-bound for the used border-box width, to satisfy
     the equation in CSS2.1 10.3.3. This test exercises scenarios where this
     mechanism "props up" the BFC's border-box enough to make its border-box
     collide width the float's margin-box, resulting in it needing to be moved
     down below the float. -->
<!-- NOTE: This testcase-variant actually has "width:stretch" (and
     vendor-prefixed equivalents) rather than "auto", but I think the effect
     should be the same, since the "stretch" and "auto" sizing keywords are
     equivalent in most cases. (Though: in practice, WebKit and Gecko are both
     more-eager-to-wrap here, with their vendor-prefixed "stretch" values, as
     compared to with "auto"... I'm not sure whether or not there's a good
     reason for that, so this test is named with ".tentative" for now.) -->
<link rel="match" href="floats-wrap-bfc-with-margin-001-ref.html">
<script>
  const MARGIN_VALS = [-30, -20, -17,
                       // Values -16 through -1 are non-interoperable and are
                       // split off to a separate test.
                       0, 5, 10, 14
                       // Values over 15 are non-interoperable and are
                       // split off to a separate test.
                      ];
  const HORIZ_SIDES = ["left", "right"]; // Used for 'float:*' and 'margin-*'.
  const DIRECTION_VALS = ["ltr", "rtl"];

  function newDivWithClassAndParent(className, parent) {
    let elem = document.createElement("div");
    if (className) {
      elem.classList.add(className);
    }
    parent.appendChild(elem);
    return elem;
  }
  function generateGroup(directionVal, floatVal, marginPropSuffix) {
    let group = newDivWithClassAndParent("group", document.body);
    group.style.direction = directionVal;
    const marginPropName = "margin-" + marginPropSuffix;

    for (let v of MARGIN_VALS) {
      let container = newDivWithClassAndParent("container", group);
      let float = newDivWithClassAndParent("float", container);
      float.style.cssFloat = floatVal;

      let bfc = newDivWithClassAndParent("bfc", container);
      bfc.style[marginPropName] = v + "px";
    }
  }
  function go() {
    for (let directionVal of DIRECTION_VALS) {
      for (let floatVal of HORIZ_SIDES) {
        for (let marginPropSuffix of HORIZ_SIDES) {
          generateGroup(directionVal, floatVal, marginPropSuffix);
        }
      }
    }
    // Note: the "reftest-wait" usage here isn't strictly necessary; it just
    // helps ensure that we actually make it through all of the above JS and
    // populate this document with the content that we want to render.
    // (Specifically: if we e.g. throw a JS exception somewhere early in both
    // the testcase and reference case, then the "reftest-wait" class will
    // never be removed; and that will cause the test run to be classified
    // as a failure, rather than a trivial "pass" with a visual comparison of
    // two blank documents.)
    document.documentElement.removeAttribute("class");
  }
</script>
<style>
.group {
  width: 500px;
  border: 1px solid black;
}
.container {
  /* This is the container that holds our float+bfc.  We make it an
     inline-block so that we can test a bunch of these in a row.  */
  display: inline-block;
  vertical-align: top;
  width: 30px;
  height: 40px;
  /* This border and margin are just cosmetic, to avoid overlap between
   * adjacent containers within a row. */
  border: 1px solid gray;
  margin-left: 30px;
}

.float {
  /* We'll set the float property elsewhere (to 'right' or 'left'). */
  width: 7px;
  height: 8px;
  background: fuchsia;
  border: 1px solid purple;
  /* Each .float's margin-box (which the corresponding .bfc's border-box cannot
   * overlap) is 14px wide:
   *   7px content + 2px horizontal border + 5px horizontal margin
   * Note that we're intentionally using a nonzero 'margin' here, to be sure
   * the UA is using the float's margin-box (and not one of its other
   * boxes) for this non-overlapping calculation. */
  margin: 1px 3px 1px 2px;
}
.bfc {
  /* Each .bfc's border-box width is 2px (from the border) plus whatever we
   * resolve 'width:auto' to, which is influenced by the particular choice of
   * 'margin' values (and the available space). */
  display: flow-root;
  background: aqua;
  height: 15px;
  border: 1px solid blue;

  /* https://drafts.csswg.org/css-sizing-4/#stretch-fit-sizing */
  width: -moz-available;
  width: -webkit-fill-available;
  width: stretch;
}
</style>
<body onload="go()">
</body>
</html>