File: replaced-element-042.html

package info (click to toggle)
thunderbird 1%3A140.3.1esr-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,608,628 kB
  • sloc: cpp: 7,671,698; javascript: 5,901,131; ansic: 3,898,955; python: 1,413,270; xml: 653,997; asm: 462,284; java: 180,948; sh: 113,489; makefile: 20,460; perl: 14,288; objc: 13,059; yacc: 4,583; pascal: 3,352; lex: 1,720; ruby: 1,222; exp: 762; sql: 715; awk: 580; php: 436; lisp: 430; sed: 70; csh: 10
file content (93 lines) | stat: -rw-r--r-- 3,451 bytes parent folder | download | duplicates (8)
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
<!DOCTYPE html>
<meta charset="utf-8">
<title>CSS aspect-ratio: replaced element with box-sizing</title>
<link rel="help" href="https://drafts.csswg.org/css-sizing-4/#aspect-ratio">
<link rel="help" href="https://drafts.csswg.org/css2/visudet.html#min-max-widths">
<link rel="author" title="Oriol Brufau" href="mailto:obrufau@igalia.com">

<style>
canvas {
  box-sizing: border-box;
  aspect-ratio: 1;
  width: auto;
  height: auto;
  background: black;
}
</style>

<div id="log"></div>

<!--
From https://drafts.csswg.org/css2/visudet.html#min-max-widths

> for replaced elements with an intrinsic ratio and both `width` and `height` specified as `auto`,
> the algorithm is as follows:
>
> Select from the table the resolved height and width values for the appropriate constraint violation.
> Take the max-width and max-height as max(min, max) so that min ≤ max holds true.
> In this table w and h stand for the results of the width and height computations
> ignoring the `min-width`, `min-height`, `max-width` and `max-height` properties.
> Normally these are the intrinsic width and height, but they may not be
> in the case of replaced elements with intrinsic ratios.

Note the testcases below ensure that w/h is 1 to match the provided `aspect-ratio`,
which didn't exist in CSS2.

Also note that `aspect-ratio: 1` refers to the border-box due to `box-sizing`,
so we need to perform all calculations using border-box sizes.
-->

<!--
w = 100 + 0 = 100
h = 50 + 50 = 100
max-width = 50
max-height = 70
Constraint Violation = "(w > max-width) and (h > max-height), where (max-width/w ≤ max-height/h)"
Resolved Width = max-width = 50
Resolved Height = max(min-height, max-width * h/w) = max(0, 50*100/100) = 50
-->
<canvas width="100" height="50" style="max-width: 50px; max-height: 70px; padding-top: 50px"
        data-expected-width="50" data-expected-height="50"></canvas>

<!--
w = 50 + 50 = 100
h = 100 + 0 = 100
max-width = 70
max-height = 50
Constraint Violation = "(w > max-width) and (h > max-height), where (max-width/w > max-height/h)"
Resolved Width = max(min-width, max-height * w/h) = max(0, 50*100/100) = 50
Resolved Height = max-height = 50
-->
<canvas width="50" height="100" style="max-width: 70px; max-height: 50px; padding-left: 50px"
        data-expected-width="50" data-expected-height="50"></canvas>

<!--
w = 50 + 50 = 100
h = 100 + 0 = 100
min-width = 150
min-height = 175
Constraint Violation = "(w < min-width) and (h < min-height), where (min-width/w ≤ min-height/h)"
Resolved Width = min(max-width, min-height * w/h) = min(∞, 175*100/100) = 175
Resolved Height = min-height = 175
-->
<canvas width="50" height="100" style="min-width: 150px; min-height: 175px; padding-left: 50px"
        data-expected-width="175" data-expected-height="175"></canvas>

<!--
w = 100 + 0 = 100
h = 50 + 50 = 100
min-width = 175
min-height = 150
Constraint Violation = "(w < min-width) and (h < min-height), where (min-width/w > min-height/h)"
Resolved Width = min-width = 175
Resolved Height = min(max-height, min-width * h/w) = min(∞, 175*100/100) = 175
-->
<canvas width="100" height="50" style="min-width: 175px; min-height: 150px; padding-top: 50px"
        data-expected-width="175" data-expected-height="175"></canvas>

<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/resources/check-layout-th.js"></script>
<script>
checkLayout("canvas");
</script>