-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtemplate.html
108 lines (91 loc) · 1.96 KB
/
template.html
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
<html>
<head>
<style>
* {
box-sizing: border-box;
}
body,
section {
width: 800px;
height: 418px;
position: relative;
}
body.debug .text {
background: palegreen;
}
body.debug .domain {
background: palevioletred;
}
body.debug .spy {
background: orange;
}
.rectangle {
position: absolute;
top: 10px;
right: 10px;
bottom: 10px;
left: 10px;
border: 3px solid #000;
}
.container {
position: absolute;
top: 30px;
right: 30px;
left: 30px;
bottom: 30px;
display: flex;
flex-direction: column;
}
.text {
flex: 1;
line-height: 12ch;
}
.domain {
margin-top: 30px;
font-size: 22px;
}
.domain:empty {
display: none;
}
.spy {
font-size: 16px;
display: inline-block;
}
</style>
</head>
<body class="|body-css|">
<section>
<div class="rectangle"></div>
<div class="container">
<div class="text">
<div class="spy">|text|</div>
</div>
<div class="domain">|footer|</div>
</div>
</section>
</body>
<script>
function updateSize() {
const wrapper = document.querySelector('.text').getBoundingClientRect()
const text = document.querySelector('.spy')
let inside = true
let size = 16
while (inside) {
const pos = text.getBoundingClientRect()
const height = pos.height
const width = pos.width
if (height > wrapper.height || width > wrapper.width) {
inside = false
size -= 1
} else {
size += 1
}
text.style.fontSize = size + 'px'
text.style.lineHeight = size * 0.9 + 'px'
}
}
;(function () {
updateSize()
})()
</script>
</html>