回答編集履歴
5
コードの変更。何度もすみません。。
test
CHANGED
@@ -108,11 +108,11 @@
|
|
108
108
|
|
109
109
|
const COLORS = [ // この配列は都合上あるものなので気にしなくていいです。
|
110
110
|
|
111
|
-
["ff0000","
|
111
|
+
["ff0000","dd0000"]
|
112
|
-
|
112
|
+
|
113
|
-
,["0000ff","0000
|
113
|
+
,["0000ff","0000dd"]
|
114
|
-
|
114
|
+
|
115
|
-
,["00ff00","00
|
115
|
+
,["00ff00","00dd00"]
|
116
116
|
|
117
117
|
];
|
118
118
|
|
@@ -194,7 +194,7 @@
|
|
194
194
|
|
195
195
|
```html
|
196
196
|
|
197
|
-
<div class="wrapper">
|
197
|
+
<div id="red" class="wrapper">
|
198
198
|
|
199
199
|
<div class="chld">
|
200
200
|
|
@@ -212,7 +212,7 @@
|
|
212
212
|
|
213
213
|
|
214
214
|
|
215
|
-
<div class="wrapper">
|
215
|
+
<div id="blue" class="wrapper">
|
216
216
|
|
217
217
|
<div class="chld">
|
218
218
|
|
@@ -226,12 +226,30 @@
|
|
226
226
|
|
227
227
|
</div>
|
228
228
|
|
229
|
+
</div>
|
230
|
+
|
231
|
+
|
232
|
+
|
233
|
+
<div id="green" class="wrapper">
|
234
|
+
|
229
235
|
<div class="chld">
|
230
236
|
|
231
237
|
要素5
|
232
238
|
|
233
239
|
</div>
|
234
240
|
|
241
|
+
<div class="chld">
|
242
|
+
|
243
|
+
要素6
|
244
|
+
|
245
|
+
</div>
|
246
|
+
|
247
|
+
<div class="chld">
|
248
|
+
|
249
|
+
要素7
|
250
|
+
|
251
|
+
</div>
|
252
|
+
|
235
253
|
</div>
|
236
254
|
|
237
255
|
```
|
@@ -268,6 +286,14 @@
|
|
268
286
|
|
269
287
|
|
270
288
|
|
289
|
+
.chld:last-child {
|
290
|
+
|
291
|
+
margin-bottom: 0;
|
292
|
+
|
293
|
+
}
|
294
|
+
|
295
|
+
|
296
|
+
|
271
297
|
.wrapper {
|
272
298
|
|
273
299
|
margin: 4vh 5vw;
|
@@ -276,17 +302,31 @@
|
|
276
302
|
|
277
303
|
z-index: -1;
|
278
304
|
|
279
|
-
background-image: url(http://placehold.jp/5x5.png);
|
280
|
-
|
281
305
|
background-repeat: repeat;
|
282
306
|
|
283
307
|
}
|
284
308
|
|
285
309
|
|
286
310
|
|
311
|
+
#red {
|
312
|
+
|
313
|
+
background-image: url(http://placehold.jp/ff0000/dd0000/50x50.png);
|
314
|
+
|
315
|
+
}
|
316
|
+
|
317
|
+
|
318
|
+
|
287
|
-
|
319
|
+
#blue {
|
320
|
+
|
288
|
-
|
321
|
+
background-image: url(http://placehold.jp/0000ff/0000dd/50x50.png);
|
322
|
+
|
323
|
+
}
|
324
|
+
|
325
|
+
|
326
|
+
|
289
|
-
|
327
|
+
#green {
|
328
|
+
|
329
|
+
background-image: url(http://placehold.jp/00ff00/00dd00/50x50.png);
|
290
330
|
|
291
331
|
}
|
292
332
|
|
4
コードの編集
test
CHANGED
@@ -40,12 +40,26 @@
|
|
40
40
|
|
41
41
|
</div>
|
42
42
|
|
43
|
+
|
44
|
+
|
43
|
-
<div class="chld group-
|
45
|
+
<div class="chld group-3">
|
44
46
|
|
45
47
|
要素5
|
46
48
|
|
47
49
|
</div>
|
48
50
|
|
51
|
+
<div class="chld group-3">
|
52
|
+
|
53
|
+
要素6
|
54
|
+
|
55
|
+
</div>
|
56
|
+
|
57
|
+
<div class="chld group-3">
|
58
|
+
|
59
|
+
要素7
|
60
|
+
|
61
|
+
</div>
|
62
|
+
|
49
63
|
```
|
50
64
|
|
51
65
|
|
3
コードの編集
test
CHANGED
@@ -88,15 +88,27 @@
|
|
88
88
|
|
89
89
|
var nth = 0;
|
90
90
|
|
91
|
-
const GROUP_NUM =
|
91
|
+
const GROUP_NUM = 3;
|
92
|
+
|
93
|
+
|
94
|
+
|
92
|
-
|
95
|
+
const COLORS = [ // この配列は都合上あるものなので気にしなくていいです。
|
96
|
+
|
93
|
-
|
97
|
+
["ff0000","880088"]
|
98
|
+
|
94
|
-
|
99
|
+
,["0000ff","000088"]
|
100
|
+
|
101
|
+
,["00ff00","008800"]
|
102
|
+
|
103
|
+
];
|
104
|
+
|
105
|
+
|
106
|
+
|
95
|
-
for(let i=
|
107
|
+
for(let i=0; i < GROUP_NUM; i++){
|
96
|
-
|
97
|
-
|
98
|
-
|
108
|
+
|
109
|
+
|
110
|
+
|
99
|
-
let n = document.getElementsByClassName("group-"+i).length;
|
111
|
+
let n = document.getElementsByClassName("group-"+(i+1)).length;
|
100
112
|
|
101
113
|
|
102
114
|
|
@@ -118,140 +130,142 @@
|
|
118
130
|
|
119
131
|
z-index: -1;
|
120
132
|
|
133
|
+
background-image: url(http://placehold.jp/${COLORS[i][0]}/${COLORS[i][1]}/50x50.png);
|
134
|
+
|
135
|
+
background-repeat: repeat;
|
136
|
+
|
137
|
+
}`;
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
document.head.innerHTML += "<style>"+css+"</style>";
|
142
|
+
|
143
|
+
nth += n;
|
144
|
+
|
145
|
+
}
|
146
|
+
|
147
|
+
|
148
|
+
|
149
|
+
```
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
本当はcss(またはsassとか?)だけで済ましたかったのですが、私の力不足でjsに頼ってしまいました…すみません。。
|
154
|
+
|
155
|
+
|
156
|
+
|
157
|
+
[jsFiddle](https://jsfiddle.net/namnium1125/o2tvc1b3/)
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
この回答で言いたいことは、
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
「実装できなくはないけど、**『※背景用のDIV(要素)を加えることはできない場合』なんて仕様は無くした方が良い**」
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
ということです。「js使うといいよ」という意味ではないです。
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
私の回答よりスマートなものはあるかもしれませんが、とにかく「回りくどい表現になってしまうよ」ということが言いたいです。
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
ちなみに、その仕様がなければdivで囲むだけで済みます。
|
178
|
+
|
179
|
+
|
180
|
+
|
181
|
+
```html
|
182
|
+
|
183
|
+
<div class="wrapper">
|
184
|
+
|
185
|
+
<div class="chld">
|
186
|
+
|
187
|
+
要素1
|
188
|
+
|
189
|
+
</div>
|
190
|
+
|
191
|
+
<div class="chld">
|
192
|
+
|
193
|
+
要素2
|
194
|
+
|
195
|
+
</div>
|
196
|
+
|
197
|
+
</div>
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
<div class="wrapper">
|
202
|
+
|
203
|
+
<div class="chld">
|
204
|
+
|
205
|
+
要素3
|
206
|
+
|
207
|
+
</div>
|
208
|
+
|
209
|
+
<div class="chld">
|
210
|
+
|
211
|
+
要素4
|
212
|
+
|
213
|
+
</div>
|
214
|
+
|
215
|
+
<div class="chld">
|
216
|
+
|
217
|
+
要素5
|
218
|
+
|
219
|
+
</div>
|
220
|
+
|
221
|
+
</div>
|
222
|
+
|
223
|
+
```
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
```css
|
228
|
+
|
229
|
+
* {
|
230
|
+
|
231
|
+
margin: 0;
|
232
|
+
|
233
|
+
padding: 0;
|
234
|
+
|
235
|
+
}
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
.chld {
|
240
|
+
|
241
|
+
/* position: relative;
|
242
|
+
|
243
|
+
margin: 6vh 10vw; */
|
244
|
+
|
245
|
+
margin-bottom: 6vh;
|
246
|
+
|
247
|
+
width: 80vw;
|
248
|
+
|
249
|
+
height: 10vh;
|
250
|
+
|
251
|
+
background-color: #888888;
|
252
|
+
|
253
|
+
}
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
.wrapper {
|
258
|
+
|
259
|
+
margin: 4vh 5vw;
|
260
|
+
|
261
|
+
padding: 2vh 5vw;
|
262
|
+
|
263
|
+
z-index: -1;
|
264
|
+
|
121
265
|
background-image: url(http://placehold.jp/5x5.png);
|
122
266
|
|
123
267
|
background-repeat: repeat;
|
124
268
|
|
125
|
-
}`;
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
document.head.innerHTML += "<style>"+css+"</style>";
|
130
|
-
|
131
|
-
nth += n;
|
132
|
-
|
133
|
-
}
|
134
|
-
|
135
|
-
```
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
本当はcss(またはsassとか?)だけで済ましたかったのですが、私の力不足でjsに頼ってしまいました…すみません。。
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
[jsFiddle](https://jsfiddle.net/namnium1125/o2tvc1b3/)
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
この回答で言いたいことは、
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
「実装できなくはないけど、**『※背景用のDIV(要素)を加えることはできない場合』なんて仕様は無くした方が良い**」
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
ということです。「js使うといいよ」という意味ではないです。
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
私の回答よりスマートなものはあるかもしれませんが、とにかく「回りくどい表現になってしまうよ」ということが言いたいです。
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
ちなみに、その仕様がなければdivで囲むだけで済みます。
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
```html
|
168
|
-
|
169
|
-
<div class="wrapper">
|
170
|
-
|
171
|
-
<div class="chld">
|
172
|
-
|
173
|
-
要素1
|
174
|
-
|
175
|
-
</div>
|
176
|
-
|
177
|
-
<div class="chld">
|
178
|
-
|
179
|
-
要素2
|
180
|
-
|
181
|
-
</div>
|
182
|
-
|
183
|
-
</div>
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
<div class="wrapper">
|
188
|
-
|
189
|
-
<div class="chld">
|
190
|
-
|
191
|
-
要素3
|
192
|
-
|
193
|
-
</div>
|
194
|
-
|
195
|
-
<div class="chld">
|
196
|
-
|
197
|
-
要素4
|
198
|
-
|
199
|
-
</div>
|
200
|
-
|
201
|
-
<div class="chld">
|
202
|
-
|
203
|
-
要素5
|
204
|
-
|
205
|
-
</div>
|
206
|
-
|
207
|
-
</div>
|
208
|
-
|
209
|
-
```
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
```css
|
214
|
-
|
215
|
-
* {
|
216
|
-
|
217
|
-
margin: 0;
|
218
|
-
|
219
|
-
padding: 0;
|
220
|
-
|
221
|
-
}
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
.chld {
|
226
|
-
|
227
|
-
/* position: relative;
|
228
|
-
|
229
|
-
margin: 6vh 10vw; */
|
230
|
-
|
231
|
-
margin-bottom: 6vh;
|
232
|
-
|
233
|
-
width: 80vw;
|
234
|
-
|
235
|
-
height: 10vh;
|
236
|
-
|
237
|
-
background-color: #888888;
|
238
|
-
|
239
|
-
}
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
.wrapper {
|
244
|
-
|
245
|
-
margin: 4vh 5vw;
|
246
|
-
|
247
|
-
padding: 2vh 5vw;
|
248
|
-
|
249
|
-
z-index: -1;
|
250
|
-
|
251
|
-
background-image: url(http://placehold.jp/5x5.png);
|
252
|
-
|
253
|
-
background-repeat: repeat;
|
254
|
-
|
255
269
|
}
|
256
270
|
|
257
271
|
|
2
css編集
test
CHANGED
@@ -102,7 +102,7 @@
|
|
102
102
|
|
103
103
|
let css =
|
104
104
|
|
105
|
-
`
|
105
|
+
`div:nth-of-type(${nth+1})::before {
|
106
106
|
|
107
107
|
content: "";
|
108
108
|
|
1
コード編集
test
CHANGED
@@ -168,13 +168,13 @@
|
|
168
168
|
|
169
169
|
<div class="wrapper">
|
170
170
|
|
171
|
-
<div class="chld
|
171
|
+
<div class="chld">
|
172
172
|
|
173
173
|
要素1
|
174
174
|
|
175
175
|
</div>
|
176
176
|
|
177
|
-
<div class="chld
|
177
|
+
<div class="chld">
|
178
178
|
|
179
179
|
要素2
|
180
180
|
|