回答編集履歴

2

コード追記

2020/08/13 14:54

投稿

hatena19
hatena19

スコア33761

test CHANGED
@@ -25,3 +25,239 @@
25
25
 
26
26
 
27
27
  [サクッとグリッドCSSを理解して、クライアントワークに使う | 新宿のホームページ制作会社 ITTI(イッティ)](https://www.itti.jp/web-design/quick-css-grid/)
28
+
29
+
30
+
31
+ ---
32
+
33
+ とりあえず理想のレイアウト画像に近いレイアウトのものを作成してみました。
34
+
35
+ 参考にしてください。
36
+
37
+
38
+
39
+ ```html
40
+
41
+ <section class="main__section">
42
+
43
+ <div class="left_col">
44
+
45
+ <h2 class="section__header">「stay Iroha as Live」</h2>
46
+
47
+ <div class="section__paragraph">
48
+
49
+ <p class="paragraph">
50
+
51
+ テキストテキストテキスト<br>
52
+
53
+ 屋久島の地で、、、いろはで、感じてほしいこと。<br>
54
+
55
+ <br>
56
+
57
+ 作っていきたい空間。<br>
58
+
59
+ 丸さんたちの想い。<br>
60
+
61
+ 暮らしの体験宿、いろは<br>
62
+
63
+ <br>
64
+
65
+ English version About iroha.
66
+
67
+ </p>
68
+
69
+ </div>
70
+
71
+ <button class="section__button">
72
+
73
+ Read more
74
+
75
+ </button>
76
+
77
+ </div>
78
+
79
+ <div class="right_col">
80
+
81
+ <img src="https://placehold.jp/600x400.png" alt="" class="section__photo">
82
+
83
+ <img src="https://placehold.jp/600x400.png" alt="" class="section__photo">
84
+
85
+ </div>
86
+
87
+ </section>
88
+
89
+ ```
90
+
91
+
92
+
93
+ ```css
94
+
95
+ .main__section {
96
+
97
+ display: flex;
98
+
99
+ position: relative;
100
+
101
+ padding: 1px;
102
+
103
+ max-width: 1200px;
104
+
105
+ margin: 0 auto;
106
+
107
+ }
108
+
109
+ .left_col {
110
+
111
+ width: 60%;
112
+
113
+ }
114
+
115
+ .right_col {
116
+
117
+ width: 38%;
118
+
119
+ }
120
+
121
+
122
+
123
+ .section__header{
124
+
125
+ font-size: 40px;
126
+
127
+ font-family: 'Toppan Bunkyu Midashi Mincho';
128
+
129
+ font-weight: bold;
130
+
131
+ letter-spacing: 0.05em;
132
+
133
+ margin-top: 20px;
134
+
135
+ margin-left: 20px;
136
+
137
+ }
138
+
139
+ .section__paragraph{
140
+
141
+ margin-top: 76px;
142
+
143
+ }
144
+
145
+ .paragraph{
146
+
147
+ font-size: 25px;
148
+
149
+ font-family: 'Toppan Bunkyu Mincho'; font-weight: normal;
150
+
151
+ line-height: 1.4;
152
+
153
+ text-shadow: 0px 3px 6px #707070;
154
+
155
+ }
156
+
157
+ .section__button{
158
+
159
+ display: block;
160
+
161
+ width: 200px;
162
+
163
+ height: 60px;
164
+
165
+ border: 1px solid;
166
+
167
+ margin: 50px auto 0;
168
+
169
+ background-color: rgba(0, 0, 0, 0);
170
+
171
+ font-family: 'Toppan Bunkyu Midashi Mincho'; font-weight: bold;
172
+
173
+ font-size: 20px;
174
+
175
+ letter-spacing: 0.1em;
176
+
177
+ }
178
+
179
+
180
+
181
+ .section__photo{
182
+
183
+ width: 100%;
184
+
185
+ height: auto;
186
+
187
+ margin-bottom: 20px;
188
+
189
+ }
190
+
191
+
192
+
193
+ .main__section::before {
194
+
195
+ content: "";
196
+
197
+ display: block;
198
+
199
+ position: absolute;
200
+
201
+ top: 20%;
202
+
203
+ bottom: 20%;
204
+
205
+ left: 20%;
206
+
207
+ right: 20%;
208
+
209
+ background-color: #F8F8F8;
210
+
211
+ z-index: -1;
212
+
213
+ }
214
+
215
+ ```
216
+
217
+ [Codepenサンプル](https://codepen.io/hatena19/pen/XWdXVQw)
218
+
219
+
220
+
221
+ こまかい位置やサイズは適当ですのでお好みで修正してください。
222
+
223
+
224
+
225
+ ** HTML **
226
+
227
+ `main__section`クラスの子要素に、`left_col` `right_col`クラス要素を追加した。2カラムになるように`main__section`クラスに display: flex; を設定した。
228
+
229
+
230
+
231
+ `left_col`内には、テキストの要素群を配置し、`right_col`内には画像(img要素)を配置した。
232
+
233
+
234
+
235
+ `section__graybox`は装飾のみの要素であり、コンテンツとしては無意味なものなので削除しました。
236
+
237
+ この装飾はCSSの方で実装します。
238
+
239
+
240
+
241
+ ** CSS **
242
+
243
+ 全体のコンテナである `.main__section` の幅は、`max-width` で最大幅のみ設定します。
244
+
245
+ `margin: 0 auto;`で左右中央寄せします。
246
+
247
+
248
+
249
+ 全体のレイアウトを決める幅などは % で指定します。
250
+
251
+ 各要素間の余白はmarginで固定値で設定します。
252
+
253
+ こうすることで、レスポンシブ対応(画面幅が変わってもおおきくレイアウトがくずれない)できます。
254
+
255
+
256
+
257
+ 背面のグレーのブロック(`section__graybox`で実装されていたもの)は、`::before`疑似要素で実装しました。このような他の要素に重ねるものは`position: absolute;`で配置します。
258
+
259
+
260
+
261
+ スマホ用には別にメディアクエリを使って1カラムのレイアウトにするといいと思います。
262
+
263
+ スマホ用にどのようなレイアウトをお望みかは不明なので、今回はこれは実装してません。

1

説明の改善

2020/08/13 14:54

投稿

hatena19
hatena19

スコア33761

test CHANGED
@@ -1,4 +1,6 @@
1
1
  margin-top margin-left に絶対値でレイアウトの位置決めしていますが、これはやめましょう。
2
+
3
+ (各要素間の余白のためにmarginを使うのはいいですが、レイアウトのために使うのはNGです。)
2
4
 
3
5
  同様に、position: absolute; での位置決めもやめましょう。
4
6