teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

2

cssとjsのコードを質問文に追加しました

2021/10/18 04:16

投稿

ttpk
ttpk

スコア338

title CHANGED
File without changes
body CHANGED
@@ -1,75 +1,37 @@
1
1
  ご覧いただきありがとうございます。
2
2
  商品一覧ページを作成しているのですが、商品数が多くてスクロールしなければ
3
3
  全て表示できない場合でもスクロールバーが表示されません。
4
-
5
- 3つ目、4つ目の商品名などの情報表示されない原因はどこにあるのでしょうか。
4
+ 3つ目、4つ目の商品名などの情報表示されない原因はどこにあるのでしょうか。
6
- ※cssとjsは字数制限のため載せられませんでした。
7
-
8
5
  ```html
9
-
10
6
  <!DOCTYPE html>
11
7
  <html lang="ja">
12
-
13
8
  <head>
14
9
  <meta charset="utf-8">
15
- <title>サイトタイトル</title>
10
+ <title></title>
16
- <meta name="description" content="ディスクリプションを入力">
17
11
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
18
12
  <link rel="stylesheet" href="css/style.css">
19
- <!-- [if lt IE 9] -->
20
13
  <script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
21
-
22
- <!-- [endif] -->
23
14
  <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-cookie/1.4.1/jquery.cookie.min.js"></script>
24
15
  <script src="js/app.js"></script>
25
16
  </head>
26
-
27
17
  <body>
28
- <!----- header----->
29
18
  <header>
30
19
  <div class="logo">
31
- <a href="top.php">極楽<br>酒造</a>
20
+ <a href=""></a>
32
21
  </div>
33
22
  <h1>
34
- 商品ページ </h1>
23
+                 </h1>
35
24
  <div class="modal-back"></div>
36
25
  <div class="cart-modal">
37
- <h2 class="post_title">カートに入れた商品</h2>
26
+ <h2 class="post_title"></h2>
38
27
  </div>
39
- <div class="cart-box"><a class="cart-check" href="#">カートを見る(<span id="cart-count">0</span>)</a></div>
28
+ <div class="cart-box"><a class="cart-check" href="">(<span id="cart-count">0</span>)</a></div>
40
29
  <script>
41
30
  cart_change();
42
31
 
43
32
  </script>
44
- <ul class="drop">
33
+
45
- <li><a href="top.php">HOME</a></li>
46
- <li>日本酒 <ul class="drop_menu">
47
- <li><a href="product.php?id=5">純米酒</a></li>
48
- <li><a href="product.php?id=6">果実酒</a></li>
49
- <li><a href="product.php?id=7">日本酒ギフト</a></li>
50
- </ul>
51
- </li>
52
- <li>ビール <ul class="drop_menu">
53
- <li><a href="product.php?id=9">瓶ビール</a></li>
54
- <li><a href="product.php?id=10">缶ビール</a></li>
55
- <li><a href="product.php?id=11">ビールギフト</a></li>
56
- </ul>
57
- </li>
58
- <li>おつまみ <ul class="drop_menu">
59
- <li><a href="product.php?id=12">エイヒレ</a></li>
60
- <li><a href="product.php?id=13">ウインナー</a></li>
61
- <li><a href="product.php?id=14">奈良漬け</a></li>
62
- </ul>
63
- </li>
64
- <li>コーヒー <ul class="drop_menu">
65
- <li><a href="product.php?id=15">ボトルコーヒー</a></li>
66
- <li><a href="product.php?id=16">コーヒーギフト</a></li>
67
- </ul>
68
- </li>
69
- </ul>
70
34
  </header>
71
- <!----- /header ----->
72
- <!----- main ----->
73
35
  <div class="main">
74
36
  <div class="product-corner">
75
37
  <script>
@@ -78,27 +40,21 @@
78
40
  </script>
79
41
  <div class="product-box">
80
42
  <div class="product-item">
81
- <img src="http://localhost:8888/js_advance2/img/IMG_4652.jpg" alt="" class="product-img">
43
+ <img src="" alt="" class="product-img">
82
44
  <span class="product-name">
83
- 奈良漬け詰め合わせ(牛蒡と瓜) </span>
45
+ </span>
84
46
  <span class="product-price">
85
- ¥700(税込) </span>
47
+ </span>
86
48
  <div class="info-box">
87
- <div id="2" class="fav_button"><span class="fav_icon"></span><span class="__text">お気に入り<p id="sumi_2"></p></span>
49
+ <div id="2" class="fav_button"><span class="fav_icon"></span><span class="__text"><p id="sumi_2"></p></span>
88
50
  </div>
89
51
  <script>
90
52
  checked_inspect(product_id);
91
-
92
53
  </script>
93
54
  <select id="cnt_2">
94
55
  <option value="1">1</option>
95
- <option value="2">2</option>
96
- <option value="3">3</option>
97
- <option value="4">4</option>
98
- <option value="5">5</option>
99
56
  </select>
100
57
  <button class="cart_in" value="2">
101
- カートに入れる
102
58
  </button>
103
59
  </div>
104
60
  </div>
@@ -107,99 +63,356 @@
107
63
 
108
64
  </script>
109
65
  <div class="product-item">
110
- <img src="http://localhost:8888/js_advance2/img/IMG_4651.jpg" alt="" class="product-img">
66
+ <img src="" alt="" class="product-img">
111
67
  <span class="product-name">
112
- 奈良漬詰め合わせ(西瓜ときゅうり) </span>
68
+ </span>
113
69
  <span class="product-price">
114
- ¥700(税込) </span>
70
+ </span>
115
71
  <div class="info-box">
116
- <div id="4" class="fav_button"><span class="fav_icon"></span><span class="__text">お気に入り<p id="sumi_4"></p></span>
72
+ <div id="4" class="fav_button"><span class="fav_icon"></span><span class="__text"><p id="sumi_4"></p></span>
117
73
  </div>
118
74
  <script>
119
75
  checked_inspect(product_id);
120
-
121
76
  </script>
122
77
  <select id="cnt_4">
123
78
  <option value="1">1</option>
124
- <option value="2">2</option>
125
- <option value="3">3</option>
126
- <option value="4">4</option>
127
- <option value="5">5</option>
128
79
  </select>
129
80
  <button class="cart_in" value="4">
130
- カートに入れる
131
81
  </button>
132
82
  </div>
133
83
  </div>
134
84
  <script>
135
85
  var product_id = 6;
136
-
137
86
  </script>
138
87
  <div class="product-item">
139
- <img src="http://localhost:8888/js_advance2/img/IMG_2812.jpg" alt="" class="product-img">
88
+ <img src="" alt="" class="product-img">
140
89
  <span class="product-name">
141
- 金亀漬 </span>
90
+ </span>
142
91
  <span class="product-price">
143
- ¥500(税込) </span>
92
+ </span>
144
93
  <div class="info-box">
145
- <div id="6" class="fav_button"><span class="fav_icon"></span><span class="__text">お気に入り<p id="sumi_6"></p></span>
94
+ <div id="6" class="fav_button"><span class="fav_icon"></span><span class="__text"><p id="sumi_6"></p></span>
146
95
  </div>
147
96
  <script>
148
97
  checked_inspect(product_id);
149
-
150
98
  </script>
151
99
  <select id="cnt_6">
152
100
  <option value="1">1</option>
153
- <option value="2">2</option>
154
- <option value="3">3</option>
155
- <option value="4">4</option>
156
- <option value="5">5</option>
157
101
  </select>
158
102
  <button class="cart_in" value="6">
159
- カートに入れる
160
103
  </button>
161
104
  </div>
162
105
  </div>
163
106
  <script>
164
107
  var product_id = 7;
165
-
166
108
  </script>
167
109
  <div class="product-box">
168
110
  <div class="product-item">
169
- <img src="http://localhost:8888/js_advance2/img/IMG_6866.jpg" alt="" class="product-img">
111
+ <img src="" alt="" class="product-img">
170
112
  <span class="product-name">
171
- 賀茂茄子の奈良漬け </span>
113
+ </span>
172
114
  <span class="product-price">
173
- ¥400(税込) </span>
115
+ </span>
174
116
  <div class="info-box">
175
- <div id="7" class="fav_button"><span class="fav_icon"></span><span class="__text">お気に入り<p id="sumi_7"></p></span>
117
+ <div id="7" class="fav_button"><span class="fav_icon"></span><span class="__text"><p id="sumi_7"></p></span>
176
118
  </div>
177
119
  <script>
178
120
  checked_inspect(product_id);
179
-
180
121
  </script>
181
122
  <select id="cnt_7">
182
123
  <option value="1">1</option>
183
- <option value="2">2</option>
184
- <option value="3">3</option>
185
- <option value="4">4</option>
186
- <option value="5">5</option>
187
124
  </select>
188
125
  <button class="cart_in" value="7">
189
- カートに入れる
190
126
  </button>
191
127
  </div>
192
128
  </div>
193
129
  </div>
194
130
  </div>
195
131
  </div>
196
- <!----- /main ----->
197
-
198
- <!----- footer ----->
199
- <footer>©︎gokurakusyuzou 2001-2021</footer>
132
+ <footer></footer>
200
- <!----- /footer ----->
201
133
  </body>
202
-
203
134
  </html>
204
135
 
136
+ ```
137
+
138
+ ```css
139
+ * {
140
+ margin: 0;
141
+ padding: 0;
142
+ box-sizing: border-box;
143
+ list-style: none;
144
+ }
145
+ header{
146
+ height: 25px;
147
+ padding-bottom: 200px;
148
+ }
149
+ .logo{
150
+ position: relative;
151
+ top: 50px;
152
+ left: 70px;
153
+ }
154
+ .logo a{
155
+ position: relative;
156
+ text-decoration: none;
157
+ }
158
+ .cart-box{
159
+ position: relative;
160
+ float: right;
161
+ top:-50px;
162
+ right: 70px;
163
+ }
164
+ .cart-modal{
165
+ display: none;
166
+ position: fixed;
167
+ z-index: 15;
168
+ top: 30%;
169
+ left: 50%;
170
+ width: 800px;
171
+ padding: 10px;
172
+ border-radius: 8px;
173
+ -webkit-transform: translate(-50%, -10%);
174
+ transform: translate(-50%, -10%);
175
+ font-size: 1.3rem;
176
+ border: 0.3rem solid #fff;
177
+ }
178
+ .modal-back{
179
+ display: none;
180
+ position: fixed;
181
+ top: 0;
182
+ left: 0;
183
+ width: 100%;
184
+ height: 100%;
185
+ z-index: 10;
186
+ }
187
+ .modal-box{
188
+ display: flex;
189
+ justify-content: space-around;
190
+ text-align: left;
191
+ }
192
+ .modal-title{
193
+ text-align: center;
194
+ padding-bottom: 15px;
195
+ }
196
+ .modal-left{
197
+ width: 450px;
198
+ }
199
+ .modal-left,.modal-center,.modal-right{
200
+ padding: 10px;
201
+ }
202
+ body {
203
+ overflow: hidden;
204
+ margin: 0;
205
+ padding: 0;
206
+ height: 100%;
207
+ }
208
+ h1{
209
+ text-align: center;
210
+ padding-top: 20px;
211
+ }
212
+ .main{
213
+ position: relative;
214
+ text-align: center;
215
+ }
216
+ .drop{
217
+ max-width: 1200px;
218
+ display: flex;
219
+ padding-top: 20px;
220
+ }
221
+
222
+ button {
223
+ cursor: pointer;
224
+ -webkit-appearance: none;
225
+ -moz-appearance: none;
226
+ appearance: none;
227
+ vertical-align: middle;
228
+ color: inherit;
229
+ font: inherit;
230
+ border: 0;
231
+ background: transparent;
232
+ padding: 0;
233
+ margin: 0;
234
+ outline: none;
235
+ border-radius: 0;
236
+ }
237
+ .product-box{
238
+ display: flex;
239
+ flex-wrap: wrap;
240
+ }
241
+ .product-corner{
242
+ z-index:10;
243
+ }
244
+ .product-item{
245
+ padding-left: 10%;
246
+ padding-bottom: 20px;
247
+ width: 50%;
248
+ height: 400px;
249
+ }
250
+ .product-price{
251
+ width: 50%;
252
+ }
253
+ .product-img{
254
+ width: 300px;
255
+ height: 200px;
256
+ }
257
+ .product-img,.product-name,.product-price{
258
+ display: block;
259
+ position: relative;
260
+ }
261
+ .product-name{
262
+ font-size: 18px;
263
+ font-weight: bold;
264
+ width: 50%;
265
+ }
266
+ .info-box{
267
+ position: absolute;
268
+ }
269
+ .fav_button {
270
+ width: 123px;
271
+ height: 48px;
272
+ border: 1px solid #9F5050;
273
+ display: -webkit-box;
274
+ display: -ms-flexbox;
275
+ display: flex;
276
+ -webkit-box-align: center;
277
+ -ms-flex-align: center;
278
+ align-items: center;
279
+ -webkit-box-pack: center;
280
+ -ms-flex-pack: center;
281
+ justify-content: center;
282
+ font-size: 12px;
283
+ font-weight: bold;
284
+ letter-spacing: 0.1em;
285
+ cursor: pointer;
286
+ white-space: nowrap;
287
+ font-size: 11px;
288
+ }
289
+ #cnt{
290
+ position: relative;
291
+ left: -80px;
292
+ }
293
+ .fav_icon {
294
+ position: relative;
295
+ width: 20px;
296
+ height: 19px;
297
+ display: inline-block;
298
+ margin-right: 10px;
299
+ }
300
+ .fav_button .fav_icon:before {
301
+ content: "";
302
+ position: absolute;
303
+ top: 0;
304
+ left: 0;
305
+ right: 0;
306
+ bottom: 0;
307
+ background-image: url(../img/fav_icon.png);
308
+ background-size: contain;
309
+ background-repeat: no-repeat;
310
+ }
311
+ .is-choosen .fav_icon:before {
312
+ opacity: 0;
313
+ }
314
+ .fav_button .fav_icon:after {
315
+ content: "";
316
+ position: absolute;
317
+ top: 0;
318
+ left: 0;
319
+ right: 0;
320
+ bottom: 0;
321
+ background-image: url(../img/fav_icon_w.png);
322
+ background-size: contain;
323
+ background-repeat: no-repeat;
324
+ opacity: 0;
325
+ }
326
+ .is-choosen .fav_icon:after {
327
+ opacity: 1;
328
+ }
329
+ .cart_in{
330
+ margin-left: 10px;
331
+ padding: 5px;
332
+ border: 1px solid #228bc8;
333
+ border-radius: 30px;
334
+ }
335
+ footer{
336
+ text-align: center;
337
+ position: fixed;
338
+ bottom: 0;
339
+ left: 0;
340
+ width: 100%;
341
+ height: 35px;
342
+ padding: 10px;
343
+ }
344
+ ```
345
+
346
+ ```Javascript
347
+
348
+ $(function(){
349
+ $(document).on('click','.fav_button',function(){
350
+ var product_id = $(this).attr('id');
351
+
352
+ var index = String(fav).indexOf(String(product_id));
353
+ if (index > -1) {
354
+ fav = fav.replace(','+product_id, "");
355
+ fav = fav.replace(product_id, "");
356
+ } else {
357
+ fav = fav + ',' + product_id;
358
+ }
359
+ $.cookie("fav_item", fav, {
360
+ expires: 1,
361
+ path: '/'
362
+ });
363
+ checked_inspect(product_id);
364
+ });
365
+
366
+ function checked_inspect(product_id) {
367
+ fav = $.cookie("fav_item");
368
+ if (String(fav).indexOf(String(product_id)) > -1) {
369
+ $('#sumi_' + product_id).text('済');
370
+ $('#' + product_id).addClass("is-choosen");
371
+ } else {
372
+ $('#sumi_' + product_id).text('登録');
373
+ $('#' + product_id).removeClass("is-choosen");
374
+ }
375
+ }
376
+ function cart_change(){
377
+ $.post("cart_count.php", {
378
+ user_id: 1
379
+ }, function(data){
380
+ $('#cart-count').text(data.count);
381
+ });
382
+ }
383
+ $(document).on('click', '.cart_in', function(){
384
+ var product_id = $(this).val();
385
+ var cnt = $('#cnt_' + product_id + ' option:selected').text();
386
+ console.log(product_id);
387
+ console.log(cnt);
388
+ $.post("cart_in.php", {
389
+ product_id: product_id,
390
+ item_count: cnt,
391
+ user_id: 1
392
+ }, function(data){
393
+ const alert1 = alertMaker(cnt);
394
+ alert(alert1());
395
+ cart_change();
396
+ });
397
+ })
398
+ function alertMaker(cnt){
399
+ return function(){
400
+ return '商品を'+cnt+'個カートに入れました。';
401
+ }
402
+ }
403
+ $(document).on('click', '.cart-check', function(){
404
+ scroll_position = $(window).scrollTop();
405
+ $('body').addClass('fixed').css({'top' : -scroll_position});
406
+ $('.cart-modal').fadeIn();
407
+ $('.modal-back').fadeIn();
408
+ cart_show();
409
+ })
410
+ function cart_show(){
411
+ $.post("cart-show.php", {
412
+ user_id: 1
413
+ }, function(data){
414
+ console.log(data.html);
415
+ $('.cart-modal').html('<h2 class="modal-title">カートに入れた商品</h2><div>'+data.html+'</div>');
416
+ });
417
+ }
205
418
  ```

1

htmlしか載せられなかった理由を追加

2021/10/18 04:16

投稿

ttpk
ttpk

スコア338

title CHANGED
File without changes
body CHANGED
@@ -3,6 +3,7 @@
3
3
  全て表示できない場合でもスクロールバーが表示されません。
4
4
 
5
5
  3つ目、4つ目の商品名などの情報を表示されない原因はどこにあるのでしょうか。
6
+ ※cssとjsは字数制限のため載せられませんでした。
6
7
 
7
8
  ```html
8
9