質問編集履歴

1

コードの具体化

2020/01/27 13:16

投稿

shiratama215
shiratama215

スコア5

test CHANGED
File without changes
test CHANGED
@@ -50,25 +50,143 @@
50
50
 
51
51
 
52
52
 
53
- CSS
54
-
55
-
56
-
57
- #header {
58
-
59
- position:fixed;
60
-
61
- width:100%;
62
-
63
- min-width:1000px;
64
-
65
- height:100px;
66
-
67
- }
68
-
69
-
70
-
71
- Javascript
53
+ コピペで再現できるように丸々作ったものを置きます
54
+
55
+
56
+
57
+ [CSS]
58
+
59
+
60
+
61
+ body{
62
+
63
+ margin:0px;
64
+
65
+ padding:0px;
66
+
67
+ }
68
+
69
+
70
+
71
+ .header_container {
72
+
73
+ position:fixed;
74
+
75
+ width:100%;
76
+
77
+ min-width:1000px;
78
+
79
+ height:100px;
80
+
81
+ background:red;
82
+
83
+ }
84
+
85
+
86
+
87
+ .header {
88
+
89
+ margin-right:auto;
90
+
91
+ margin-left:auto;
92
+
93
+ width:1000px;
94
+
95
+ min-width:1000px; /* これも入れないとscriptが動かない */
96
+
97
+ height:100%;
98
+
99
+ background:blue;
100
+
101
+ }
102
+
103
+
104
+
105
+ .backspace{ /* ヘッダーの背後に置く空白です */
106
+
107
+ height:100px;
108
+
109
+ }
110
+
111
+
112
+
113
+ .point { /* 文字の位置を示すための右寄せです */
114
+
115
+ text-align:right;
116
+
117
+ font-size:20pt;
118
+
119
+ color:orange;
120
+
121
+ }
122
+
123
+
124
+
125
+ .box_container { /* ページ本体(ヘッダー以下)の横1000px以上時の余白です */
126
+
127
+ width:100%;
128
+
129
+ height:1000px;
130
+
131
+ background:red;
132
+
133
+ }
134
+
135
+
136
+
137
+ .box { /* ページ本体部分です */
138
+
139
+ margin-right:auto;
140
+
141
+ margin-left:auto;
142
+
143
+ width:1000px;
144
+
145
+ min-width:1000px;
146
+
147
+ height:900px;
148
+
149
+ background:white;
150
+
151
+ }
152
+
153
+
154
+
155
+
156
+
157
+ [HTML]
158
+
159
+
160
+
161
+ <body>
162
+
163
+ <div class="header_container">
164
+
165
+ <div class="header">
166
+
167
+ <div class="point">端</div>
168
+
169
+ </div>
170
+
171
+ </div>
172
+
173
+ <div class="box_container">
174
+
175
+ <div class="backspace"></div>
176
+
177
+ <div class="box">
178
+
179
+ テスト<br<br><br><br><div class="point">テスト</div><br<br><br><br>テスト<br<br><br><br>テスト
180
+
181
+ </div>
182
+
183
+ </div>
184
+
185
+ </body>
186
+
187
+
188
+
189
+ [javascript]
72
190
 
73
191
 
74
192
 
@@ -76,7 +194,7 @@
76
194
 
77
195
  function Scroll() {
78
196
 
79
- document.getElementById("header").style.left = -window.scrollX + "px";
197
+ document.getElementById("header_container").style.left = -window.scrollX + "px";
80
198
 
81
199
  }
82
200
 
@@ -86,7 +204,11 @@
86
204
 
87
205
 
88
206
 
89
- 上述
207
+ Javascriptなしだとヘッダーは横スクロールできず固定されたままです。
208
+
209
+ Javascriptありだと画面サイズが1000pxを下回った時に、ページ全体の横スクロールに合わせてヘッダーも動きます。
210
+
211
+ ただiOSだとうまく動かないのです。(ヘッダーの移動がスクロール値に対して動きすぎる)
90
212
 
91
213
 
92
214