grid-align-baseline.html (6174B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>CSS Grid Layout Test: grid align baseline</title> 4 <link rel="author" title="Rossana Monteriso" href="mailto:rmonteriso@igalia.com"> 5 <link rel="help" href="https://drafts.csswg.org/css-writing-modes-4/#intro-baselines"> 6 <link rel="help" href="https://drafts.csswg.org/css-align-3/#baseline-rules"> 7 <link rel="help" href="https://drafts.csswg.org/css-align-3/#baseline-align-self"> 8 <meta name="assert" content="This test checks that baseline alignment works correctly for align-items and align-self properties"> 9 <meta name="flags" content="ahem"> 10 <link rel="stylesheet" type="text/css" href="/fonts/ahem.css" /> 11 <link rel="stylesheet" href="/css/support/grid.css"> 12 <link rel="stylesheet" href="/css/support/alignment.css"> 13 14 <style> 15 16 .grid { 17 width: 600px; 18 grid-auto-columns: 1fr; 19 position: relative; 20 margin-bottom: 20px; 21 font: 20px/1 Ahem; 22 } 23 24 .grid :nth-child(1) { background-color: blue; } 25 .grid :nth-child(2) { background-color: green; } 26 .grid :nth-child(3) { background-color: red; } 27 .grid :nth-child(4) { background-color: yellow; } 28 .grid :nth-child(5) { background-color: purple; } 29 .grid :nth-child(6) { background-color: orange; } 30 .grid :nth-child(7) { background-color: lime; } 31 .grid :nth-child(8) { background-color: lightblue; } 32 .grid :nth-child(9) { background-color: darkred; } 33 .grid :nth-child(10) { background-color: gold; } 34 .grid :nth-child(11) { background-color: salmon; } 35 36 .firstRowThirdColumn { 37 grid-row: 1; 38 grid-column: 3; 39 } 40 .firstRowFourthColumn { 41 grid-row: 1; 42 grid-column: 4; 43 } 44 .firstRowFifthColumn { 45 grid-row: 1; 46 grid-column: 5; 47 } 48 </style> 49 50 <script src="/resources/testharness.js"></script> 51 <script src="/resources/testharnessreport.js"></script> 52 <script src="/resources/check-layout-th.js"></script> 53 <script type="text/javascript"> setup({ explicit_done: true }); </script> 54 55 <body onload="document.fonts.ready.then(() => { runTests(); })"> 56 57 <div class="grid alignItemsBaseline"> 58 <div style="margin: 40px 0px;" class="firstRowFirstColumn" data-offset-x="0" data-offset-y="40" data-expected-width="200" data-expected-height="20"><div style="display:inline-block;"></div></div> 59 <div style="margin: auto 0px 0px;" class="firstRowSecondColumn" data-offset-x="200" data-offset-y="80" data-expected-width="200" data-expected-height="20"><div style="display:inline-block;"></div></div> 60 <div style="margin: 20px 0px;" class="firstRowThirdColumn" data-offset-x="400" data-offset-y="40" data-expected-width="200" data-expected-height="20"><div style="display:inline-block;"></div></div> 61 </div> 62 63 <div class="grid"> 64 <div data-expected-height="20" data-offset-y="20" class="firstRowFirstColumn alignSelfBaseline" style="height: 20px;"></div> 65 <div data-expected-height="10" data-offset-y="30" class="firstRowSecondColumn alignSelfBaseline" style="height: 10px; margin: 30px 0 10px;"></div> 66 <div data-expected-height="10" data-offset-y="30" class="firstRowThirdColumn alignSelfBaseline" style="height: 10px; margin: 20px 0 0;"></div> 67 <div data-expected-height="100" data-offset-y="0" class="firstRowFourthColumn" style="height: 100px;"></div> 68 </div> 69 70 <div class="grid"> 71 <div data-expected-height="20" data-offset-y="70" class="firstRowFirstColumn alignSelfLastBaseline" style="height: 20px;"></div> 72 <div data-expected-height="10" data-offset-y="80" class="firstRowSecondColumn alignSelfLastBaseline" style="height: 10px; margin: 30px 0 10px;"></div> 73 <div data-expected-height="10" data-offset-y="80" class="firstRowThirdColumn alignSelfLastBaseline" style="height: 10px; margin: 20px 0 0;"></div> 74 <div data-expected-height="100" data-offset-y="0" class="firstRowFourthColumn" style="height: 100px;"></div> 75 </div> 76 77 <div class="grid"> 78 <div id="baseline1" class="firstRowFirstColumn alignSelfBaseline">ahem</div> 79 <div id="baseline2" data-offset-y="0" class="firstRowSecondColumn alignSelfBaseline"><img src="/css/support/1x1-lime.png" style="height: 50px;"></div> 80 <div data-expected-height="50" data-offset-y="25" class="firstRowThirdColumn alignSelfCenter"><img src="/css/support/1x1-lime.png" style="height: 50px; vertical-align: middle"></div> 81 <div id="baseline3" data-expected-height="50" class="firstRowFourthColumn alignSelfBaseline"><img src="/css/support/1x1-lime.png" style="height: 50px; vertical-align: middle"></div> 82 <div data-expected-height="100" data-offset-y="0" class="firstRowFifthColumn" style="height: 100px;"></div> 83 </div> 84 85 <div class="grid"> 86 <div id="baseline4" class="firstRowFirstColumn alignSelfBaseline">ahem</div> 87 <div id="baseline5" class="firstRowSecondColumn alignSelfBaseline"><br><img src="/css/support/1x1-lime.png" style="height: 50px;"></div> 88 <div data-expected-height="50" data-offset-y="0" class="firstRowThirdColumn alignSelfBaseline"><img src="/css/support/1x1-lime.png" style="height: 50px; vertical-align: middle"></div> 89 <div data-expected-height="100" data-offset-y="0" class="firstRowFourthColumn" style="height: 100px;"></div> 90 </div> 91 92 <div id="log"></div> 93 94 </body> 95 96 <script> 97 98 function runTests() { 99 var baseline1 = document.getElementById("baseline1"); 100 var baseline2 = document.getElementById("baseline2"); 101 var baseline3 = document.getElementById("baseline3"); 102 var baseline4 = document.getElementById("baseline4"); 103 var baseline5 = document.getElementById("baseline5"); 104 105 checkLayout('.grid', false); 106 107 test(() => {assert_equals(baseline1.offsetTop + baseline1.offsetHeight, baseline2.offsetTop + baseline2.offsetHeight, "baseline1 and baseline2 should have the same baseline;")}, 108 "Additional Check 1"); 109 test(() => {assert_less_than(baseline3.offsetTop, 25, "baseline3 should be above the center align-selfed item;")}, "Additional Check 2"); 110 test(() => {assert_equals(baseline4.offsetTop, baseline5.offsetTop, "baseline4 and baseline5 should be top aligned with each other;")}, "Additional Check 3"); 111 test(() => {assert_greater_than(baseline4.offsetTop, 0, "baseline4 and baseline5 should be below the dominant baseline;")}, "Additional Check 4"); 112 113 done(); 114 }; 115 116 </script>