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

回答編集履歴

3

修正

2019/10/26 07:38

投稿

s8_chu
s8_chu

スコア14731

answer CHANGED
@@ -1,4 +1,4 @@
1
- flex アイテムは、デフォルトでは [`flex-wrap` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/flex-wrap)に `nowrap` が設定されていることで折り返さないようになっています。そのため、まずは Bootstrap によって用意されている [`flex-wrap` クラス](https://getbootstrap.com/docs/4.0/utilities/flex/#wrap)を使用し、 flex アイテムの折り返しを許可します。そして、 flex アイテムのうち `box` クラスが付与されたものに `w-50` クラスを付与しておきます。
1
+ flex アイテムは、デフォルトでは [`flex-wrap` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/flex-wrap)に `nowrap` が設定されていることで折り返さないようになっています。そのため、まずは Bootstrap によって用意されている [`flex-wrap` クラス](https://getbootstrap.com/docs/4.0/utilities/flex/#wrap)を使用し、 flex アイテムの折り返しを許可します。そして、一行の中に `box` クラスが適用された要素を収めるために、 flex アイテムのうち `box` クラスが付与されたものに `w-50` クラスを付与しておきます。
2
2
 
3
3
  ```HTML
4
4
  <section class="d-flex flex-wrap">
@@ -97,8 +97,7 @@
97
97
 
98
98
  ---
99
99
 
100
- ただし、 `hr` 要素は段落間における意味的な区切りを表す要素であるため、今回のような `section`
101
- 要素間での区切りを意味するような使用方法は不適切です。このような場合には、 `after` 擬似要素を使用することが出来ます ([動作確認用リンク](https://jsfiddle.net/41ghdbsq/))。
100
+ ただし、 **`hr` 要素は段落における意味的な区切りを表す**要素あるため、今回ような `section` 要素間での区切りを意味するような使用方法は不適切です。このような場合には、 `after` 擬似要素を使用することが出来ます ([動作確認用リンク](https://jsfiddle.net/41ghdbsq/))。
102
101
 
103
102
  > ##### [§ 4.4.2 The hr element](https://html.spec.whatwg.org/multipage/grouping-content.html#the-hr-element)
104
103
  > The `hr` element represents a paragraph-level thematic break, e.g. a scene change in a story, or a transition to another topic within a section of a reference book.

2

修正

2019/10/26 07:38

投稿

s8_chu
s8_chu

スコア14731

answer CHANGED
@@ -1,12 +1,12 @@
1
- flex アイテムは、デフォルトでは [`flex-wrap` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/flex-wrap)に `nowrap` が設定されていることで折り返さないようになっています。そのため、まずは Bootstrap によって用意されている [`flex-wrap` クラス](https://getbootstrap.com/docs/4.0/utilities/flex/#wrap)を使用し、 flex アイテムの折り返しを許可します。
1
+ flex アイテムは、デフォルトでは [`flex-wrap` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/flex-wrap)に `nowrap` が設定されていることで折り返さないようになっています。そのため、まずは Bootstrap によって用意されている [`flex-wrap` クラス](https://getbootstrap.com/docs/4.0/utilities/flex/#wrap)を使用し、 flex アイテムの折り返しを許可します。そして、 flex アイテムのうち `box` クラスが付与されたものに `w-50` クラスを付与しておきます。
2
2
 
3
3
  ```HTML
4
4
  <section class="d-flex flex-wrap">
5
- <div class="box box-1">
5
+ <div class="box box-1 w-50">
6
6
  <h3>Airbnbでホストするこれだけの理由</h3><br>
7
7
  <p>どんなお家やお部屋でも、Airbnbなら簡単かつ安全にシェアでき、世界中の旅好きな仲間とつながれます。 予約可能日から料金、ハウスルール、ゲストとの交流程度まで、すべて自分で決めることができます。</p>
8
8
  </div>
9
- <div class="box box-2">
9
+ <div class="box box-2 w-50">
10
10
  <h3>困ったときも安心</h3><br>
11
11
  <p>万一に備えるUS$1,000,000の財物補償、US$1,000,000の賠償責任保険が全予約に自動付帯。ホストのみなさまと建物・家財の安全をお守りするため全力で取り組んでいます。</p>
12
12
  </div>
@@ -14,18 +14,18 @@
14
14
  </section>
15
15
  ```
16
16
 
17
- 次に、 flex アイテムのうち `box` クラスが付与されたものを一行に収めるためにこれら要素に [`flex` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/flex)を使用して flex コンテナの幅に合わせて伸縮を行うようにします。このために、 `box` クラスに `flex` プロパティを追記します。
17
+ また、 flex アイテム余白は今回場合 [`margin` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/margin)ではなく [`justify-content` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/justify-content)で制御出来るため、これ使用します。
18
18
 
19
19
  ```CSS
20
20
  .box {
21
21
  text-justify: auto;
22
22
  margin-top: 2px;
23
23
  margin-bottom: 6px;
24
- flex: 1; /* 追記 */
24
+ justify-content: space-evenly; /* 追記 */
25
25
  }
26
26
  ```
27
27
 
28
- すると、最終的なコードは以下のようになり、質問者さんの実現したいことが行えます ([動作確認用リンク](https://jsfiddle.net/wu5kyc4z/))。
28
+ すると、最終的なコードは以下のようになり、質問者さんの実現したいことが行えます ([動作確認用リンク](https://jsfiddle.net/udfr4zoj/))。
29
29
  ```HTML
30
30
  <!doctype html>
31
31
  <html lang="ja">
@@ -48,21 +48,12 @@
48
48
  text-justify: auto;
49
49
  margin-top: 2px;
50
50
  margin-bottom: 6px;
51
- flex: 1; /* 追記 */
51
+ justify-content: space-evenly; /* 追記 */
52
52
  }
53
53
 
54
- .box-1 {
55
- margin-left: 4px;
56
- }
57
54
 
58
- .box-2 {
59
- margin-left: 4px;
60
- margin-right: 4px;
61
- }
62
-
63
55
  .ln {
64
- break-before: always;
56
+ border-top: 3px solid #000;
65
- color: #a9a9a9;
66
57
  width: 5%;
67
58
  }
68
59
 
@@ -81,11 +72,11 @@
81
72
  </section>
82
73
 
83
74
  <section class="d-flex flex-wrap">
84
- <div class="box box-1">
75
+ <div class="box box-1 w-50">
85
76
  <h3>Airbnbでホストするこれだけの理由</h3><br>
86
77
  <p>どんなお家やお部屋でも、Airbnbなら簡単かつ安全にシェアでき、世界中の旅好きな仲間とつながれます。 予約可能日から料金、ハウスルール、ゲストとの交流程度まで、すべて自分で決めることができます。</p>
87
78
  </div>
88
- <div class="box box-2">
79
+ <div class="box box-2 w-50">
89
80
  <h3>困ったときも安心</h3><br>
90
81
  <p>万一に備えるUS$1,000,000の財物補償、US$1,000,000の賠償責任保険が全予約に自動付帯。ホストのみなさまと建物・家財の安全をお守りするため全力で取り組んでいます。</p>
91
82
  </div>
@@ -100,4 +91,92 @@
100
91
  </body>
101
92
 
102
93
  </html>
94
+
95
+ ```
96
+
97
+
98
+ ---
99
+
100
+ ただし、 `hr` 要素は段落間における意味的な区切りを表す要素であるため、今回のような `section`
101
+ 要素間での区切りを意味するような使用方法は不適切です。このような場合には、 `after` 擬似要素を使用することが出来ます ([動作確認用リンク](https://jsfiddle.net/41ghdbsq/))。
102
+
103
+ > ##### [§ 4.4.2 The hr element](https://html.spec.whatwg.org/multipage/grouping-content.html#the-hr-element)
104
+ > The `hr` element represents a paragraph-level thematic break, e.g. a scene change in a story, or a transition to another topic within a section of a reference book.
105
+
106
+ ```CSS
107
+ .ln::after {
108
+ content: "";
109
+ margin: 0 auto;
110
+ border-top: 3px solid #000;
111
+ width: 5%;
112
+ }
113
+ ```
114
+
115
+ ```HTML
116
+ <!doctype html>
117
+ <html lang="ja">
118
+
119
+ <head>
120
+ <!-- Required meta tags -->
121
+ <meta charset="utf-8">
122
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
123
+
124
+ <!-- Bootstrap CSS -->
125
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="" crossorigin="anonymous">
126
+
127
+ <style type="text/css">
128
+ .jumbotron {
129
+ background: url(airbnb/airbnb4.png) center no-repeat;
130
+ background-size: cover;
131
+ }
132
+
133
+ .box {
134
+ text-justify: auto;
135
+ margin-top: 2px;
136
+ margin-bottom: 6px;
137
+ justify-content: space-evenly;
138
+
139
+ }
140
+
141
+
142
+ .ln::after { /* 追記 */
143
+ content: "";
144
+ margin: 0 auto;
145
+ border-top: 3px solid #000;
146
+ width: 5%;
147
+ }
148
+
149
+ </style>
150
+
151
+ <title>Airbnbでお家、アパート、お部屋をシェアしよう</title>
152
+ </head>
153
+
154
+ <body>
155
+ <header>
156
+ <div></div>
157
+ </header>
158
+ <main>
159
+ <section class="jumbotron rounded-0">
160
+ <div class="container"></div>
161
+ </section>
162
+
163
+ <section class="d-flex flex-wrap ln">
164
+ <div class="box box-1 w-50">
165
+ <h3>Airbnbでホストするこれだけの理由</h3><br>
166
+ <p>どんなお家やお部屋でも、Airbnbなら簡単かつ安全にシェアでき、世界中の旅好きな仲間とつながれます。 予約可能日から料金、ハウスルール、ゲストとの交流程度まで、すべて自分で決めることができます。</p>
167
+ </div>
168
+ <div class="box box-2 w-50">
169
+ <h3>困ったときも安心</h3><br>
170
+ <p>万一に備えるUS$1,000,000の財物補償、US$1,000,000の賠償責任保険が全予約に自動付帯。ホストのみなさまと建物・家財の安全をお守りするため全力で取り組んでいます。</p>
171
+ </div>
172
+ </section>
173
+ </main>
174
+ <!-- Optional JavaScript -->
175
+ <!-- jQuery first, then Popper.js, then Bootstrap JS -->
176
+ <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="" crossorigin="anonymous"></script>
177
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="" crossorigin="anonymous"></script>
178
+ <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="" crossorigin="anonymous"></script>
179
+ </body>
180
+
181
+ </html>
103
182
  ```

1

修正

2019/10/26 07:36

投稿

s8_chu
s8_chu

スコア14731

answer CHANGED
@@ -1,6 +1,7 @@
1
1
  flex アイテムは、デフォルトでは [`flex-wrap` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/flex-wrap)に `nowrap` が設定されていることで折り返さないようになっています。そのため、まずは Bootstrap によって用意されている [`flex-wrap` クラス](https://getbootstrap.com/docs/4.0/utilities/flex/#wrap)を使用し、 flex アイテムの折り返しを許可します。
2
2
 
3
+ ```HTML
3
- ```HTML<section class="d-flex flex-wrap">
4
+ <section class="d-flex flex-wrap">
4
5
  <div class="box box-1">
5
6
  <h3>Airbnbでホストするこれだけの理由</h3><br>
6
7
  <p>どんなお家やお部屋でも、Airbnbなら簡単かつ安全にシェアでき、世界中の旅好きな仲間とつながれます。 予約可能日から料金、ハウスルール、ゲストとの交流程度まで、すべて自分で決めることができます。</p>
@@ -10,4 +11,93 @@
10
11
  <p>万一に備えるUS$1,000,000の財物補償、US$1,000,000の賠償責任保険が全予約に自動付帯。ホストのみなさまと建物・家財の安全をお守りするため全力で取り組んでいます。</p>
11
12
  </div>
12
13
  <hr class="ln">
13
- </section>
14
+ </section>
15
+ ```
16
+
17
+ 次に、 flex アイテムのうち `box` クラスが付与されたものを一行に収めるために、これらの要素に [`flex` プロパティ](https://developer.mozilla.org/ja/docs/Web/CSS/flex)を使用して flex コンテナの幅に合わせて伸縮を行うようにします。このために、 `box` クラスに `flex` プロパティを追記します。
18
+
19
+ ```CSS
20
+ .box {
21
+ text-justify: auto;
22
+ margin-top: 2px;
23
+ margin-bottom: 6px;
24
+ flex: 1; /* 追記 */
25
+ }
26
+ ```
27
+
28
+ すると、最終的なコードは以下のようになり、質問者さんの実現したいことが行えます ([動作確認用リンク](https://jsfiddle.net/wu5kyc4z/))。
29
+ ```HTML
30
+ <!doctype html>
31
+ <html lang="ja">
32
+
33
+ <head>
34
+ <!-- Required meta tags -->
35
+ <meta charset="utf-8">
36
+ <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
37
+
38
+ <!-- Bootstrap CSS -->
39
+ <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/css/bootstrap.min.css" integrity="" crossorigin="anonymous">
40
+
41
+ <style type="text/css">
42
+ .jumbotron {
43
+ background: url(airbnb/airbnb4.png) center no-repeat;
44
+ background-size: cover;
45
+ }
46
+
47
+ .box {
48
+ text-justify: auto;
49
+ margin-top: 2px;
50
+ margin-bottom: 6px;
51
+ flex: 1; /* 追記 */
52
+ }
53
+
54
+ .box-1 {
55
+ margin-left: 4px;
56
+ }
57
+
58
+ .box-2 {
59
+ margin-left: 4px;
60
+ margin-right: 4px;
61
+ }
62
+
63
+ .ln {
64
+ break-before: always;
65
+ color: #a9a9a9;
66
+ width: 5%;
67
+ }
68
+
69
+ </style>
70
+
71
+ <title>Airbnbでお家、アパート、お部屋をシェアしよう</title>
72
+ </head>
73
+
74
+ <body>
75
+ <header>
76
+ <div></div>
77
+ </header>
78
+ <main>
79
+ <section class="jumbotron rounded-0">
80
+ <div class="container"></div>
81
+ </section>
82
+
83
+ <section class="d-flex flex-wrap">
84
+ <div class="box box-1">
85
+ <h3>Airbnbでホストするこれだけの理由</h3><br>
86
+ <p>どんなお家やお部屋でも、Airbnbなら簡単かつ安全にシェアでき、世界中の旅好きな仲間とつながれます。 予約可能日から料金、ハウスルール、ゲストとの交流程度まで、すべて自分で決めることができます。</p>
87
+ </div>
88
+ <div class="box box-2">
89
+ <h3>困ったときも安心</h3><br>
90
+ <p>万一に備えるUS$1,000,000の財物補償、US$1,000,000の賠償責任保険が全予約に自動付帯。ホストのみなさまと建物・家財の安全をお守りするため全力で取り組んでいます。</p>
91
+ </div>
92
+ <hr class="ln">
93
+ </section>
94
+ </main>
95
+ <!-- Optional JavaScript -->
96
+ <!-- jQuery first, then Popper.js, then Bootstrap JS -->
97
+ <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="" crossorigin="anonymous"></script>
98
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="" crossorigin="anonymous"></script>
99
+ <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="" crossorigin="anonymous"></script>
100
+ </body>
101
+
102
+ </html>
103
+ ```