tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

floats-wrap-bfc-with-margin-001.html (4827B)


      1 <!DOCTYPE html>
      2 <html class="reftest-wait">
      3 <meta charset="utf-8">
      4 <title>CSS Test: If a BFC's inline-axis margin is sufficiently negative such
      5  that it inflates its border-box to be too large to fit alongside a float,
      6  then it should be pushed below the float</title>
      7 <link rel="author" title="Daniel Holbert" href="mailto:dholbert@mozilla.com">
      8 <link rel="help" href="https://www.w3.org/TR/CSS21/visuren.html#floats">
      9 <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">
     10 <link rel="help" href="https://www.w3.org/TR/CSS21/visudet.html#blockwidth">
     11 <!-- For a BFC with 'width:auto', negative total inline-axis margins will
     12     effectively set a lower-bound for the used border-box width, to satisfy
     13     the equation in CSS2.1 10.3.3. This test exercises scenarios where this
     14     mechanism "props up" the BFC's border-box enough to make its border-box
     15     collide width the float's margin-box, resulting in it needing to be moved
     16     down below the float. -->
     17 <link rel="match" href="floats-wrap-bfc-with-margin-001-ref.html">
     18 <script>
     19  const MARGIN_VALS = [-30, -20, -17,
     20                       // Values -16 through -1 are non-interoperable and are
     21                       // split off to a separate test.
     22                       0, 5, 10, 14
     23                       // Values over 15 are non-interoperable and are
     24                       // split off to a separate test.
     25                      ];
     26  const HORIZ_SIDES = ["left", "right"]; // Used for 'float:*' and 'margin-*'.
     27  const DIRECTION_VALS = ["ltr", "rtl"];
     28 
     29  function newDivWithClassAndParent(className, parent) {
     30    let elem = document.createElement("div");
     31    if (className) {
     32      elem.classList.add(className);
     33    }
     34    parent.appendChild(elem);
     35    return elem;
     36  }
     37  function generateGroup(directionVal, floatVal, marginPropSuffix) {
     38    let group = newDivWithClassAndParent("group", document.body);
     39    group.style.direction = directionVal;
     40    const marginPropName = "margin-" + marginPropSuffix;
     41 
     42    for (let v of MARGIN_VALS) {
     43      let container = newDivWithClassAndParent("container", group);
     44      let float = newDivWithClassAndParent("float", container);
     45      float.style.cssFloat = floatVal;
     46 
     47      let bfc = newDivWithClassAndParent("bfc", container);
     48      bfc.style[marginPropName] = v + "px";
     49    }
     50  }
     51  function go() {
     52    for (let directionVal of DIRECTION_VALS) {
     53      for (let floatVal of HORIZ_SIDES) {
     54        for (let marginPropSuffix of HORIZ_SIDES) {
     55          generateGroup(directionVal, floatVal, marginPropSuffix);
     56        }
     57      }
     58    }
     59    // Note: the "reftest-wait" usage here isn't strictly necessary; it just
     60    // helps ensure that we actually make it through all of the above JS and
     61    // populate this document with the content that we want to render.
     62    // (Specifically: if we e.g. throw a JS exception somewhere early in both
     63    // the testcase and reference case, then the "reftest-wait" class will
     64    // never be removed; and that will cause the test run to be classified
     65    // as a failure, rather than a trivial "pass" with a visual comparison of
     66    // two blank documents.)
     67    document.documentElement.removeAttribute("class");
     68  }
     69 </script>
     70 <style>
     71 .group {
     72  width: 500px;
     73  border: 1px solid black;
     74 }
     75 .container {
     76  /* This is the container that holds our float+bfc.  We make it an
     77     inline-block so that we can test a bunch of these in a row.  */
     78  display: inline-block;
     79  vertical-align: top;
     80  width: 30px;
     81  height: 40px;
     82  /* This border and margin are just cosmetic, to avoid overlap between
     83   * adjacent containers within a row. */
     84  border: 1px solid gray;
     85  margin-left: 30px;
     86 }
     87 
     88 .float {
     89  /* We'll set the float property elsewhere (to 'right' or 'left'). */
     90  width: 7px;
     91  height: 8px;
     92  background: fuchsia;
     93  border: 1px solid purple;
     94  /* Each .float's margin-box (which the corresponding .bfc's border-box cannot
     95   * overlap) is 14px wide:
     96   *   7px content + 2px horizontal border + 5px horizontal margin
     97   * Note that we're intentionally using a nonzero 'margin' here, to be sure
     98   * the UA is using the float's margin-box (and not one of its other
     99   * boxes) for this non-overlapping calculation. */
    100  margin: 1px 3px 1px 2px;
    101 }
    102 .bfc {
    103  /* Each .bfc's border-box width is 2px (from the border) plus whatever we
    104   * resolve 'width:auto' to, which is influenced by the particular choice of
    105   * 'margin' values (and the available space). */
    106  display: flow-root;
    107  background: aqua;
    108  height: 15px;
    109  border: 1px solid blue;
    110 }
    111 </style>
    112 <body onload="go()">
    113 </body>
    114 </html>