質問編集履歴

3

ソースコード

2017/11/25 02:27

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes

2

ソースコード

2017/11/25 02:27

投稿

退会済みユーザー
test CHANGED
@@ -1 +1 @@
1
- 背景画像をブラウザの縦横サイズに合わせたい
1
+ 背景画像の縦横比率を維持したまま、コンテンツの幅に合わせて表示させたい
test CHANGED
@@ -1,37 +1,625 @@
1
- 背景画像を縦横に合わせたいのですが、コンテンツに中身がないため高さが取れな状態です。
1
+ 背景画像を可変で表示したいだけなのですが、background(背景画像)で指定した画像はheight(高さ指定)の基準がないと表示されません。レスポンシブのシングルページレイアウトを制作する上で、空コンテンツのpaddingの分高さが広がってしまうのを回避したいです。
2
+
2
-
3
+ [[CSS]ビューポート(vw, vh)とパーセント(%)、レスポンシブに適した単位の賢い使い分け方法](http://coliss.com/articles/build-websites/operation/css/viewport-vs-percentage-units-by-ire.html)
4
+
5
+ [CSS3 スマホサイト制作にかかせないbackground-sizeについて](http://www.go-next.co.jp/blog/web/html_css/1736/?utm_expid=70867113-1.DA9o90m2TYq7GIOoHLGS4Q.0)
6
+
3
- ```css
7
+ ```PHP
4
-
5
- .sample {
8
+
6
-
7
- height: 0;
8
-
9
- padding-top: 56.25%;
9
+ <!doctype html>
10
+
10
-
11
+ <html <?php language_attributes(); ?>>
12
+
13
+ <head>
14
+
11
- background: url('sample.png') 0 0 no-repeat;
15
+ <meta charset="<?php bloginfo( 'charset' ); ?>">
16
+
12
-
17
+ <meta name="viewport" content="width=device-width, initial-scale=1">
18
+
19
+ <link rel="profile" href="http://gmpg.org/xfn/11">
20
+
21
+
22
+
13
- background-size: contain;
23
+ <?php wp_head(); ?>
24
+
14
-
25
+ </head>
26
+
27
+
28
+
29
+ <body <?php body_class(); ?>>
30
+
31
+ <div id="page" class="site">
32
+
33
+
34
+
35
+
36
+
37
+ <header id="masthead" class="site-header">
38
+
39
+ <nav id="site-navigation" class="main-navigation">
40
+
41
+ <a class="navbar-brand" href="#"><img class="img-fluid navbar-brand" src="<?php echo get_template_directory_uri(); ?>/images/navi-logo.png" alt="navi-logo"></a>
42
+
43
+ <img class="img-fluid bg-header-img" src="<?php echo get_template_directory_uri(); ?>/images/bg-header.png" alt="bg-header">
44
+
45
+ <div class="navbar-collapse">
46
+
47
+ <ul class="navbar-nav">
48
+
49
+ <li class="nav-item active">
50
+
51
+ <a class="nav-link" href="#about"><img class="img-fluid navi-about-img" src="<?php echo get_template_directory_uri(); ?>/images/navi-about.png" alt="navi-about"></a>
52
+
15
- }
53
+ </li>
54
+
55
+ <li class="nav-item">
56
+
57
+ <a class="nav-link" href="#access"><img class="img-fluid navi-access-img" src="<?php echo get_template_directory_uri(); ?>/images/navi-access.png" alt="navi-access"></a>
58
+
59
+ </li>
60
+
61
+ <li class="nav-item">
62
+
63
+ <a class="nav-link" href="#news"><img class="img-fluid navi-news-img" src="<?php echo get_template_directory_uri(); ?>/images/navi-news.png" alt="navi-news"></a>
64
+
65
+ </li>
66
+
67
+ <li class="nav-item">
68
+
69
+ <a class="nav-link" href="#join"><img class="img-fluid navi-join-img" src="<?php echo get_template_directory_uri(); ?>/images/navi-join.png" alt="navi-join"></a>
70
+
71
+ </li>
72
+
73
+ <li class="nav-item">
74
+
75
+ <a class="nav-link" href="#paper-rally"><img class="img-fluid navi-rarry-img" src="<?php echo get_template_directory_uri(); ?>/images/navi-rarry.png" alt="navi-rarry"></a>
76
+
77
+ </li>
78
+
79
+ <li class="nav-item">
80
+
81
+ <a class="nav-link" href="#circle-list"><img class="img-fluid navi-circle-img" src="<?php echo get_template_directory_uri(); ?>/images/navi-circle.png" alt="navi-circle"></a>
82
+
83
+ </li>
84
+
85
+ <li class="nav-item">
86
+
87
+ <a class="nav-link" href="#contact"><img class="img-fluid navi-mail-img" src="<?php echo get_template_directory_uri(); ?>/images/navi-mail.png" alt="navi-mail"></a>
88
+
89
+ </li>
90
+
91
+ <li class="nav-item">
92
+
93
+ <a class="nav-link" href="#"><img class="img-fluid navi-twitter-img" src="<?php echo get_template_directory_uri(); ?>/images/navi-twitter.png" alt="navi-twitter"></a>
94
+
95
+ </li>
96
+
97
+ </ul>
98
+
99
+ </div>
100
+
101
+ </nav><!-- #site-navigation -->
102
+
103
+ </header><!-- #masthead -->
104
+
105
+
106
+
107
+ <div id="content" class="site-content">
16
108
 
17
109
  ```
18
110
 
19
- こちらの方法でブラウザのサイズに合わせて高さが変わるようになりますが、1段組のワンページデザインなのでpaddingが厄介になってしまいます。
20
-
21
- ```css
111
+ ```PHP
22
-
23
- .sample {
112
+
24
-
25
- height: 100vh;
26
-
27
- min-height: 450px;
28
-
29
- background: url('sample.png') center center /cover no-repeat;
113
+ <div id="primary" class="content-area">
114
+
30
-
115
+ <main id="main" class="site-main" role="main">
116
+
117
+
118
+
119
+ <section id="intro" class="intro">
120
+
121
+ <div class="container">
122
+
123
+ <div class="row">
124
+
125
+ <div class="col-md-12">
126
+
127
+ <div class="section-header">
128
+
129
+ <h1><img class="img-fluid title-intro" src="<?php echo get_template_directory_uri(); ?>/images/title-intro.png" alt="title-intro"></h1>
130
+
31
- }
131
+ </div>
132
+
133
+ <p class="lead">説明テキスト>説明テキスト>説明テキスト>説明テキスト>説明テキスト>説明テキスト>説明テキスト説明テキスト>説明テキスト>説明テキスト>説明テキスト>説明テキスト>説明テキスト>説明テキスト</p>
134
+
135
+ </div>
136
+
137
+ </div>
138
+
139
+ </div>
140
+
141
+ </section><!-- .intro -->
142
+
143
+
144
+
145
+ <section id="about" class="about">
146
+
147
+ <div class="container">
148
+
149
+ <div class="section-header">
150
+
151
+ <h2><img class="img-fluid title-about" src="<?php echo get_template_directory_uri(); ?>/images/title-about.png" alt="title-about"></h2>
152
+
153
+ </div>
154
+
155
+ <div class="about-boxes">
156
+
157
+ <div class="row">
158
+
159
+ <div class="col-md-3 col-sm-6">
160
+
161
+ <div class="about-circle">
162
+
163
+ <div class="about-text">
164
+
165
+ <h3><img class="img-fluid about-item" src="<?php echo get_template_directory_uri(); ?>/images/title-circle.png" alt="title-circle"></h3>
166
+
167
+ <p>BAROQUE</p>
168
+
169
+ </div>
170
+
171
+ </div>
172
+
173
+ </div>
174
+
175
+ <div class="col-md-3 col-sm-6">
176
+
177
+ <div class="about-circle">
178
+
179
+ <div class="about-text">
180
+
181
+ <h3><img class="img-fluid about-item" src="<?php echo get_template_directory_uri(); ?>/images/title-organizer.png" alt="title-organizer"></h3>
182
+
183
+ <p>うづき</p>
184
+
185
+ </div>
186
+
187
+ </div>
188
+
189
+ </div>
190
+
191
+ <div class="col-md-3 col-sm-6">
192
+
193
+ <div class="about-circle">
194
+
195
+ <div class="about-text">
196
+
197
+ <h3><img class="img-fluid about-item" src="<?php echo get_template_directory_uri(); ?>/images/title-booth.png" alt="title-booth"></h3>
198
+
199
+ <p>未定</p>
200
+
201
+ </div>
202
+
203
+ </div>
204
+
205
+ </div>
206
+
207
+ <div class="col-md-3 col-sm-6">
208
+
209
+ <div class="about-circle">
210
+
211
+ <div class="about-text">
212
+
213
+ <h3><img class="img-fluid about-item" src="<?php echo get_template_directory_uri(); ?>/images/title-date.png" alt="title-date"></h3>
214
+
215
+ <p>2018/3/11</p>
216
+
217
+ </div>
218
+
219
+ </div>
220
+
221
+ </div>
222
+
223
+ </div>
224
+
225
+ </div>
226
+
227
+ </div>
228
+
229
+ </section><!-- .about -->
32
230
 
33
231
  ```
34
232
 
233
+ ```scss
234
+
235
+ /*--------------------------------------------------------------
236
+
237
+ # Body
238
+
239
+ --------------------------------------------------------------*/
240
+
241
+ .section-header {
242
+
243
+ margin-bottom: 4rem;
244
+
245
+ }
246
+
247
+
248
+
249
+ /*--------------------------------------------------------------
250
+
251
+ # Buttons
252
+
253
+ --------------------------------------------------------------*/
254
+
255
+ .btn {
256
+
257
+ display: inline-block;
258
+
259
+ font-weight: 400;
260
+
261
+ text-align: center;
262
+
263
+ white-space: nowrap;
264
+
265
+ vertical-align: middle;
266
+
267
+ -webkit-user-select: none;
268
+
269
+ -moz-user-select: none;
270
+
271
+ -ms-user-select: none;
272
+
273
+ user-select: none;
274
+
275
+ border: .1rem solid transparent;
276
+
277
+ padding: 1rem 4rem;
278
+
279
+ font-size: 1rem;
280
+
281
+ line-height: 1.5;
282
+
283
+ border-radius: .4rem;
284
+
285
+ }
286
+
287
+
288
+
289
+ .btn-access {
290
+
291
+ background-color: $white;
292
+
293
+ color: $blue;
294
+
295
+ border: .2rem solid $blue;
296
+
297
+ }
298
+
299
+
300
+
301
+ .btn-join {
302
+
303
+ background-color: $white;
304
+
305
+ color: $green;
306
+
307
+ border: .2rem solid $green;
308
+
309
+ }
310
+
311
+
312
+
313
+ .btn-contact {
314
+
35
- こちらの方法もありましたが、縦横の比率が上手く取れません。
315
+ background-color: transparent;
316
+
36
-
317
+ color: $white;
318
+
37
- ご教示いただければ幸いです。何卒よろしくお願いいたします。
319
+ border: .2rem solid $white;
320
+
321
+ cursor: pointer;
322
+
323
+ }
324
+
325
+
326
+
327
+ /*--------------------------------------------------------------
328
+
329
+ # Navigation
330
+
331
+ --------------------------------------------------------------*/
332
+
333
+ .main-navigation .bg-header-img {
334
+
335
+ position: fixed;
336
+
337
+ top: 0;
338
+
339
+ left: 0;
340
+
341
+ width: 100rem;
342
+
343
+ z-index: 100;
344
+
345
+ }
346
+
347
+
348
+
349
+ .main-navigation .navbar-brand {
350
+
351
+ position: fixed;
352
+
353
+ top: 1.6rem;
354
+
355
+ left: 13.3rem;
356
+
357
+ z-index: 200;
358
+
359
+ }
360
+
361
+
362
+
363
+ .navbar-nav .nav-item .navi-about-img {
364
+
365
+ position: fixed;
366
+
367
+ top: 4rem;
368
+
369
+ left: 22rem;
370
+
371
+ z-index: 100;
372
+
373
+ }
374
+
375
+
376
+
377
+ .navbar-nav .nav-item .navi-access-img {
378
+
379
+ position: fixed;
380
+
381
+ top: 4rem;
382
+
383
+ left: 30rem;
384
+
385
+ z-index: 100;
386
+
387
+ }
388
+
389
+
390
+
391
+ .navbar-nav .nav-item .navi-news-img {
392
+
393
+ position: fixed;
394
+
395
+ top: 4rem;
396
+
397
+ left: 38rem;
398
+
399
+ z-index: 100;
400
+
401
+ }
402
+
403
+
404
+
405
+ .navbar-nav .nav-item .navi-join-img {
406
+
407
+ position: fixed;
408
+
409
+ top: 4rem;
410
+
411
+ left: 46rem;
412
+
413
+ z-index: 100;
414
+
415
+ }
416
+
417
+
418
+
419
+ .navbar-nav .nav-item .navi-rarry-img {
420
+
421
+ position: fixed;
422
+
423
+ top: 4rem;
424
+
425
+ left: 64rem;
426
+
427
+ z-index: 100;
428
+
429
+ }
430
+
431
+
432
+
433
+ .navbar-nav .nav-item .navi-circle-img {
434
+
435
+ position: fixed;
436
+
437
+ top: 4rem;
438
+
439
+ left: 52rem;
440
+
441
+ z-index: 100;
442
+
443
+ }
444
+
445
+
446
+
447
+ .navbar-nav .nav-item .navi-mail-img {
448
+
449
+ position: fixed;
450
+
451
+ top: 4rem;
452
+
453
+ right: 16rem;
454
+
455
+ z-index: 100;
456
+
457
+ }
458
+
459
+
460
+
461
+ .navbar-nav .nav-item .navi-twitter-img {
462
+
463
+ position: fixed;
464
+
465
+ top: 4rem;
466
+
467
+ right: 12rem;
468
+
469
+ z-index: 100;
470
+
471
+ }
472
+
473
+
474
+
475
+ /*--------------------------------------------------------------
476
+
477
+ # SiteHeader
478
+
479
+ --------------------------------------------------------------*/
480
+
481
+ .site-header {
482
+
483
+ height: 0;
484
+
485
+ padding-top: 69.44%;
486
+
487
+ background: url(images/mainImage.png) center center no-repeat;
488
+
489
+ background-size: contain;
490
+
491
+ }
492
+
493
+
494
+
495
+ /*--------------------------------------------------------------
496
+
497
+ # Intro
498
+
499
+ --------------------------------------------------------------*/
500
+
501
+ .intro {
502
+
503
+ padding: 10rem 0;
504
+
505
+ }
506
+
507
+
508
+
509
+ .title-intro {
510
+
511
+ @include media-breakpoint-down(sm) {
512
+
513
+ margin: 0 auto;
514
+
515
+ }
516
+
517
+ }
518
+
519
+
520
+
521
+ .intro p {
522
+
523
+ text-align: center;
524
+
525
+ }
526
+
527
+
528
+
529
+ /*--------------------------------------------------------------
530
+
531
+ # About
532
+
533
+ --------------------------------------------------------------*/
534
+
535
+ .about {
536
+
537
+ position: relative;
538
+
539
+ padding: 2rem 0 4rem 0;
540
+
541
+ background: url(images/bg-about.png) center /contain no-repeat;
542
+
543
+ }
544
+
545
+
546
+
547
+ .about-boxes {
548
+
549
+ position: absolute;
550
+
551
+ top: 43rem;
552
+
553
+ right: 0;
554
+
555
+ bottom: auto;
556
+
557
+ left: 0;
558
+
559
+ width: 1050px;
560
+
561
+ height: 240px;
562
+
563
+ margin: 0 auto;
564
+
565
+ }
566
+
567
+
568
+
569
+ .about-img {
570
+
571
+ position: absolute;
572
+
573
+ top: 32rem;
574
+
575
+ left: 64rem;
576
+
577
+ @include media-breakpoint-down(sm) {
578
+
579
+ margin: 0 auto;
580
+
581
+ }
582
+
583
+ }
584
+
585
+
586
+
587
+ .about .about-circle {
588
+
589
+ width: 15rem;
590
+
591
+ height: 15rem;
592
+
593
+ border-radius: 50%;
594
+
595
+ background-color: $white;
596
+
597
+ }
598
+
599
+
600
+
601
+ .about .about-circle .about-text {
602
+
603
+ padding-top: 4rem
604
+
605
+ }
606
+
607
+
608
+
609
+ .about .about-circle .about-text h3,
610
+
611
+ .about .about-circle .about-text p {
612
+
613
+ text-align: center;
614
+
615
+ }
616
+
617
+
618
+
619
+ .about .about-circle .about-text p {
620
+
621
+ margin-top: 2rem;
622
+
623
+ }
624
+
625
+ ```

1

ソースコード

2017/11/25 02:25

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
File without changes