回答編集履歴
2
追記
answer
CHANGED
@@ -50,4 +50,43 @@
|
|
50
50
|
```
|
51
51
|
|
52
52
|
imgタグだと画像のゆがみを防ぐために、object-fit が必要ですが、IEは非対応。
|
53
|
-
background-image だと、background-size: cover; ですが、これはIEでも対応。
|
53
|
+
background-image だと、background-size: cover; ですが、これはIEでも対応。
|
54
|
+
|
55
|
+
追記
|
56
|
+
---
|
57
|
+
コメントより
|
58
|
+
> ちなみにお教えいただいたbackground-imageにて背景画像を指定した場合、背景画像の上にもう一枚小さな画像を重ねて中央表示をさせるにはどのようにしたらいいかご存知でしょうか。
|
59
|
+
|
60
|
+
background-* プロパティは , で区切って複数設定できます。
|
61
|
+
例えば、背景画像を領域全体に表示させて、縦横150pxの画像を中央に表示させる場合は下記のようにななります。
|
62
|
+
|
63
|
+
```css
|
64
|
+
#top-wrapper {
|
65
|
+
padding: 0;
|
66
|
+
width: 100%;
|
67
|
+
position: relative;
|
68
|
+
height: 633px;
|
69
|
+
background-image: url(./images/staypageimg/150x150.png),
|
70
|
+
url(./images/staypageimg/topimage.jpg);
|
71
|
+
background-size: 150px 150px ,cover;
|
72
|
+
background-repeat: no-repeat;
|
73
|
+
background-position: center;
|
74
|
+
}
|
75
|
+
```
|
76
|
+
|
77
|
+
background で各background-* プロパティをまとめて設定することもできます。
|
78
|
+
|
79
|
+
```css
|
80
|
+
#top-wrapper {
|
81
|
+
padding: 0;
|
82
|
+
width: 100%;
|
83
|
+
position: relative;
|
84
|
+
height: 633px;
|
85
|
+
background: center/150px 150px no-repeat url(./images/staypageimg/150x150.png),
|
86
|
+
center/cover no-repeat url(./images/staypageimg/topimage.jpg);
|
87
|
+
}
|
88
|
+
```
|
89
|
+
|
90
|
+
[Codepenサンプル](https://codepen.io/hatena19/pen/qBZBMpm)
|
91
|
+
|
92
|
+
[background - CSS: カスケーディングスタイルシート | MDN](https://developer.mozilla.org/ja/docs/Web/CSS/background)
|
1
説明追記
answer
CHANGED
@@ -27,4 +27,27 @@
|
|
27
27
|
}
|
28
28
|
|
29
29
|
(以下略)
|
30
|
-
```
|
30
|
+
```
|
31
|
+
|
32
|
+
|
33
|
+
---
|
34
|
+
ただ、背景画像なら、imgタグではなく、cssの background-image で表示させる方法をお勧めします。
|
35
|
+
|
36
|
+
```css
|
37
|
+
#top-wrapper {
|
38
|
+
padding: 0;
|
39
|
+
width: 100%;
|
40
|
+
position: relative;
|
41
|
+
height: 633px;
|
42
|
+
background-image: url(./images/staypageimg/topimage.jpg);
|
43
|
+
background-size: cover;
|
44
|
+
}
|
45
|
+
|
46
|
+
/* 追加 */
|
47
|
+
#sub-navigation ul {
|
48
|
+
background-color: #ececec;
|
49
|
+
}
|
50
|
+
```
|
51
|
+
|
52
|
+
imgタグだと画像のゆがみを防ぐために、object-fit が必要ですが、IEは非対応。
|
53
|
+
background-image だと、background-size: cover; ですが、これはIEでも対応。
|