回答編集履歴
4
中央配置の方法を追加しました。
answer
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
こ
|
1
|
+
フレックスボックスを使えば子要素を中央に配置することができます。
|
2
2
|
```css
|
3
3
|
#top{
|
4
4
|
display: flex;
|
@@ -10,4 +10,28 @@
|
|
10
10
|
width: 100%;
|
11
11
|
height: 100vh;
|
12
12
|
}
|
13
|
+
```
|
14
|
+
もし子要素に高さと横幅を指定できれば下のような方法もあります。
|
15
|
+
```css
|
16
|
+
#top{
|
17
|
+
position: relative;
|
18
|
+
background-image: url(images/abc.jpg);
|
19
|
+
background-size: cover;
|
20
|
+
background-position: center center;
|
21
|
+
width: 100%;
|
22
|
+
height: 100vh;
|
23
|
+
}
|
24
|
+
|
25
|
+
#top h1 {
|
26
|
+
position: absolute;
|
27
|
+
top: 0;
|
28
|
+
bottom: 0;
|
29
|
+
left: 0;
|
30
|
+
right: 0;
|
31
|
+
width: 300px;
|
32
|
+
height: 100px;
|
33
|
+
margin: auto;
|
34
|
+
background-color: #fcc;
|
35
|
+
text-align: center;
|
36
|
+
}
|
13
37
|
```
|
3
コードの修正
answer
CHANGED
@@ -4,7 +4,7 @@
|
|
4
4
|
display: flex;
|
5
5
|
justify-content: center; /* 左右中央 */
|
6
6
|
align-items: center; /* 上下中央 */
|
7
|
-
background-image: url(
|
7
|
+
background-image: url(images/abc.jpg);
|
8
8
|
background-size: cover;
|
9
9
|
background-position: center center;
|
10
10
|
width: 100%;
|
2
コードの修正
answer
CHANGED
@@ -8,6 +8,6 @@
|
|
8
8
|
background-size: cover;
|
9
9
|
background-position: center center;
|
10
10
|
width: 100%;
|
11
|
-
height:
|
11
|
+
height: 100vh;
|
12
12
|
}
|
13
13
|
```
|
1
コードの変更
answer
CHANGED
@@ -1,9 +1,13 @@
|
|
1
1
|
こういうのはどうでしょうか。
|
2
2
|
```css
|
3
|
-
#top
|
3
|
+
#top{
|
4
4
|
display: flex;
|
5
5
|
justify-content: center; /* 左右中央 */
|
6
6
|
align-items: center; /* 上下中央 */
|
7
|
+
background-image: url(../images/common/sample/sample.jpg);
|
8
|
+
background-size: cover;
|
9
|
+
background-position: center center;
|
10
|
+
width: 100%;
|
7
|
-
height:
|
11
|
+
height: 30vh;
|
8
12
|
}
|
9
13
|
```
|