-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Expand file tree
/
Copy pathposition-relative-stretch-height-001.html
More file actions
75 lines (65 loc) · 2.32 KB
/
Copy pathposition-relative-stretch-height-001.html
File metadata and controls
75 lines (65 loc) · 2.32 KB
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
<!DOCTYPE html>
<title>CSS Flexbox: relative position percentage top with height: stretch containing block</title>
<link rel="help" href="https://drafts.csswg.org/css-flexbox/#definite-sizes">
<link rel="help" href="https://drafts.csswg.org/css-position-3/#valdef-top-percentage">
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#stretch-fit-sizing">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<style>
body {
margin: 0;
}
.green {
width: 20px;
height: 20px;
background: green;
position: relative;
}
</style>
<!-- 1. height: stretch against definite parent -->
<div style="height: 200px;">
<div id="t1-item" style="height: stretch;">
<div class="green" id="t1" style="top: 50%;"></div>
</div>
</div>
<!-- 2. height: stretch against auto parent (indefinite) -->
<div>
<div id="t2-item" style="height: stretch;">
<div class="green" id="t2" style="top: 50%;"></div>
</div>
</div>
<!-- 3. height: stretch inside stretched flex item (definite per 9.8) -->
<div style="display: flex; height: 200px;">
<div>
<div id="t3-item" style="height: stretch;">
<div class="green" id="t3" style="top: 50%;"></div>
</div>
</div>
</div>
<!-- 4. height: stretch inside auto-height column flex item (indefinite) -->
<div style="display: flex; flex-direction: column;">
<div style="flex-grow: 1;">
<div id="t4-item" style="height: stretch;">
<div class="green" id="t4" style="top: 50%;"></div>
</div>
</div>
</div>
<script>
function offsetFromItem(greenId, itemId) {
var green = document.getElementById(greenId);
var item = document.getElementById(itemId);
return green.getBoundingClientRect().top - item.getBoundingClientRect().top;
}
test(function() {
assert_equals(offsetFromItem('t1', 't1-item'), 100);
}, 'height: stretch against definite parent, top: 50%');
test(function() {
assert_equals(offsetFromItem('t2', 't2-item'), 0);
}, 'height: stretch against auto parent, top: 50%');
test(function() {
assert_equals(offsetFromItem('t3', 't3-item'), 100);
}, 'height: stretch inside stretched flex item, top: 50%');
test(function() {
assert_equals(offsetFromItem('t4', 't4-item'), 0);
}, 'height: stretch inside auto-height column flex item, top: 50%');
</script>