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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174
|
<!DOCTYPE html>
<link rel="help" href="https://drafts.csswg.org/css-align/#distribution-block">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
@import "/fonts/ahem.css";
body {
font: 10px/1 Ahem;
}
td {
padding: 0;
height: 50px;
}
td:nth-child(2) {
font-size: 20px;
}
.valign-top td {
vertical-align: top;
}
.valign-middle td {
vertical-align: middle;
}
.valign-bottom td {
vertical-align: bottom;
}
.valign-middle-short td {
vertical-align: middle;
height: 10px;
}
.valign-bottom-short td {
vertical-align: bottom;
height: 10px;
}
.valign-baseline td {
vertical-align: baseline;
}
.alignc-start td {
align-content: start;
}
.alignc-center td {
align-content: unsafe center;
}
.alignc-end td {
align-content: unsafe end;
}
.alignc-center-short td {
align-content: unsafe center;
height: 10px;
}
.alignc-end-short td {
align-content: unsafe end;
height: 10px;
}
.alignc-baseline td {
align-content: baseline;
}
.alignc-safe-center td {
align-content: safe center;
}
.alignc-safe-end td {
align-content: safe end;
}
.alignc-safe-center-short td {
align-content: safe center;
height: 10px;
}
.alignc-safe-end-short td {
align-content: safe end;
height: 10px;
}
</style>
<table border="0" id="ref" class="valign-baseline">
<tr>
<td><div class="content1">first<br>second</div></td>
<td><div class="content2">first<br>second</div></td>
<td><div class="content3">first<br>second<br>third</div></td>
</tr>
</table>
<table border="0" id="target" class="alignc-baseline">
<tr>
<td><div class="content1">first<br>second</div></td>
<td><div class="content2">first<br>second</div></td>
<td><div class="content3">first<br>second<br>third</div></td>
</tr>
</table>
<script>
function testEquivalence(target, ref) {
assert_equals(target.querySelector('.content1').offsetTop,
ref.querySelector('.content1').offsetTop, 'The first cell content top');
assert_equals(target.querySelector('.content2').offsetTop,
ref.querySelector('.content2').offsetTop, 'The second cell content top');
assert_equals(target.querySelector('.content3').offsetTop,
ref.querySelector('.content3').offsetTop, 'The third cell conten topt');
}
const ref = document.querySelector('#ref');
const target = document.querySelector('#target');
const TALL = 50;
// *-short specifies `height: 10px`, but cells ignore it, and the actual height
// is the maximum content height in the row.
const SHORT = 40;
const C1HEIGHT = 10 * 2;
test(() => {
ref.className = 'valign-top';
target.className = 'alignc-start';
testEquivalence(target, ref);
assert_equals(target.querySelector('.content1').offsetTop, 0);
}, 'vertical-align:top and align-content:start are equivalent');
test(() => {
ref.className = 'valign-middle';
target.className = 'alignc-center';
testEquivalence(target, ref);
assert_equals(target.querySelector('.content1').offsetTop, (TALL - C1HEIGHT) / 2);
ref.className = 'valign-middle-short';
target.className = 'alignc-center-short';
testEquivalence(target, ref);
assert_equals(target.querySelector('.content1').offsetTop, (SHORT - C1HEIGHT) / 2);
}, 'vertical-align:middle and `align-content:unsafe center` are equivalent');
test(() => {
ref.className = 'valign-bottom';
target.className = 'alignc-end';
testEquivalence(target, ref);
assert_equals(target.querySelector('.content1').offsetTop, TALL - C1HEIGHT);
ref.className = 'valign-bottom-short';
target.className = 'alignc-end-short';
testEquivalence(target, ref);
assert_equals(target.querySelector('.content1').offsetTop, SHORT - C1HEIGHT);
}, 'vertical-align:bottom and `align-content:unsafe end` are equivalent');
test(() => {
ref.className = 'valign-baseline';
target.className = 'alignc-baseline';
testEquivalence(target, ref);
}, 'vertical-align:baseline and align-content:baseline are equivalent');
test(() => {
ref.className = 'valign-middle';
target.className = 'alignc-safe-center';
testEquivalence(target, ref);
assert_equals(target.querySelector('.content1').offsetTop, (TALL - C1HEIGHT) / 2);
}, 'vertical-align:middle and `align-content:safe center` are equivalent if the container is tall');
test(() => {
ref.className = 'valign-bottom';
target.className = 'alignc-safe-end';
testEquivalence(target, ref);
assert_equals(target.querySelector('.content1').offsetTop, TALL - C1HEIGHT);
}, 'vertical-align:bottom and `align-content:safe end` are equivalent if the container is tall');
test(() => {
ref.className = 'alignc-center-short';
target.className = 'alignc-safe-center-short';
testEquivalence(target, ref);
}, '`align-content:safe center` is equivalent to `unsafe center` even if the specified `height` is short');
test(() => {
ref.className = 'alignc-end-short';
target.className = 'alignc-safe-end-short';
}, '`align-content:safe end` is equivalent to `unsafe end` even if the specified `height` is short');
</script>
|