-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
102 lines (83 loc) · 4.73 KB
/
index.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
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>overflow vs padding-right / padding-bottom</title>
<!-- Google Search Console -->
<meta name="google-site-verification" content="ls7kuvIKSqVa_dcixqKvFwl393swvYMkHCkG-xtlCj0">
<!-- Global Site Tag (gtag.js) - Google Analytics -->
<script async src="https://www.googletagmanager.com/gtag/js?id=G-LP3ZQV2R3M"></script>
<script>window.dataLayer=window.dataLayer||[];function gtag(){dataLayer.push(arguments)}gtag('js',new Date());gtag('config','G-LP3ZQV2R3M');gtag('config','UA-106501-6');</script>
<!-- Google AdSense -->
<script data-ad-client="ca-pub-6475907504235292" async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<style>
*, ::before, ::after { box-sizing: border-box; }
html { font-family: sans-serif; }
body { overflow-y: scroll; }
h1 { font-size: 1.4rem; margin-top: 0; }
h2 { font-size: 1.1rem; margin-bottom: 0; }
pre { margin: 0; }
/* 通常版 : Firefox だと padding-right・padding-bottom が効かなくなる */
pre.normal {
width: 100%;
height: 5rem;
overflow: scroll;
border: 1px solid #ccc;
padding: 1rem;
background: #f0f0f0;
}
/* 修正版 : 基本デザインはラッパー側で行う */
div.fixed {
width: 100%;
height: 5rem;
overflow: scroll;
border: 1px solid #ccc;
padding: 1rem 0 0 1rem; /* 余計なバッティングを避けるため、右と下は余白を付けないでおく */
background: #f0f0f0;
}
/* padding-bottom 代わりの要素を作る */
div.fixed::after {
content: "";
display: block;
width: 1px;
height: 1rem; /* padding-bottom にしたい値 */
}
/* 中の pre 要素は inline-block にしておき、末尾に自身の ::after 擬似要素が配置できるようにしておく */
div.fixed > pre {
display: inline-block;
}
/* padding-right 代わりの要素を作る */
div.fixed > pre::after {
content: "";
display: inline-block;
width: 1rem; /* padding-right にしたい値 */
height: 1px;
}
/* テスト用・議事要素に色を付ける */
.fixed-demo::after,
.fixed-demo > pre::after {
background: red;
}
</style>
<script>
// #toggle ボタンで .fixed 要素に対し .fixed-demo クラスをトグルする
document.addEventListener('DOMContentLoaded', () => {
document.getElementById('toggle').addEventListener('click', () => {
document.querySelector('.fixed').classList.toggle('fixed-demo');
});
});
</script>
</head>
<body>
<div style="margin: 0 auto; width: 80%;">
<h1>overflow でスクロールバーを表示させると padding-right・padding-bottom が効かなくなる事象と対策</h1>
<h2>通常版</h2>
<pre class="normal">Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br><br><br><br><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</pre>
<h2>修正版 <input type="button" id="toggle" value="擬似要素表示切替" style="float: right;"></h2>
<div class="fixed">
<pre>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.<br><br><br><br><br>Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</pre>
</div>
</div>
</body>
</html>