wpt / css / css-grid / alignment / grid-calc-margins-explicit-row.html

Status: PASS | Duration: 8ms | Subtests: 1/1 | Open test on wpt.live | Open ref on wpt.live | wpt.fyi

/css/css-grid/alignment/grid-calc-margins-explicit-row.html

<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Test: calc() margin on a grid item with explicit row placement</title>
<link rel="author" title="Sammy Gill" href="mailto:sammy.gill@apple.com">
<link rel="help" title="6.4 Grid Item Margins and Paddings" href="https://drafts.csswg.org/css-grid/#item-margins">
<link rel="match" href="../reference/grid-calc-margins-explicit-row-ref.html">
<meta name="assert" content="A percentage in a calc() margin on a grid item resolves against the inline size of its containing block (the grid area).">
<style>
  #grid {
      display: grid;
      background: grey;
      grid-template-columns: 200px;
      grid-template-rows: 100px;
  }
  #item {
      grid-row: 1 / 2;
      width: 50px;
      height: 50px;
      /* margin % resolves against the grid area inline size (200px):
         30% -> 60px, + 10px -> 70px left offset. */
      margin-left: calc(10px + 30%);
      background: green;
  }
</style>
<p>The test passes if the left edge of the green box is 70px from the left edge of the grey grid.</p>
<div id="grid">
    <div id="item"></div>
</div>

/css/css-grid/reference/grid-calc-margins-explicit-row-ref.html

<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS Grid Layout Reference: calc() margin on a grid item with explicit row placement</title>
<link rel="author" title="Sammy Gill" href="mailto:sammy.gill@apple.com">
<!-- Same layout achieved with a resolved fixed margin instead of calc(). -->
<style>
  #grid {
      display: grid;
      background: grey;
      grid-template-columns: 200px;
      grid-template-rows: 100px;
  }
  #item {
      grid-row: 1 / 2;
      width: 50px;
      height: 50px;
      margin-left: 70px;
      background: green;
  }
</style>
<p>The test passes if the left edge of the green box is 70px from the left edge of the grey grid.</p>
<div id="grid">
    <div id="item"></div>
</div>