質問編集履歴

2

修正

2018/11/02 11:28

投稿

tunnel
tunnel

スコア30

test CHANGED
@@ -1 +1 @@
1
- カラーボックスを他の画像の大きさと合わせたい
1
+ 画像の大きさと合わせたい
test CHANGED
@@ -1,6 +1,18 @@
1
+ 2つ、画像のサイズと合わせたいものがあります。
2
+
3
+ レスポンシブにしたいので画面サイズに伴って大きも変化させたいです。
4
+
5
+ bootstrapのグリッドを使ってます。
6
+
7
+ #カラーボックス
8
+
1
- newsBox-1〜6まであるうち2だけが画像ではなく背景に色をつけただけのカラーボックスになってます。
9
+ newsBox-1〜6まであるうち2だけが画像ではなく背景に色をつけただけのカラーボックスになってます。
2
-
10
+
3
- 画像は{width: 100%, height: auto}にしてるのですが、カラーボックスをこの画像の大きさと揃えるにはどうしたらよでしょうか
11
+ 2にはhtmlでstyleタグで画像のデフォルトサイズを指定してあり、双方cssは{width: 100%, height: auto}にしてるのですが2だけサイズが違ます
12
+
13
+ #:before
14
+
15
+ :beforeで画像に被せてる半透明の黒幕です。
4
16
 
5
17
  ```html
6
18
 

1

コード変更

2018/11/02 11:28

投稿

tunnel
tunnel

スコア30

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  ```html
6
6
 
7
-        <div class="newsBox row">
7
+ <div class="newsBox row">
8
8
 
9
9
  <div class="newsBox-1 newsB col-xs-12 col-sm-6 col-md-4">
10
10
 
@@ -36,7 +36,7 @@
36
36
 
37
37
  <div class="img-2">
38
38
 
39
- <div class="img-box"></div>
39
+ <div class="img-box" style="width: 500px;height: 306px"></div>
40
40
 
41
41
  <h3>RESULT</h3>
42
42
 
@@ -162,61 +162,95 @@
162
162
 
163
163
  border-radius: 5px;
164
164
 
165
+ padding: 0 1px;
166
+
165
167
  }
166
168
 
167
169
 
168
170
 
169
171
  .img-box {
170
172
 
173
+ width: 100%;
174
+
175
+ height: auto;
176
+
177
+ background-color: lightgreen;
178
+
179
+ overflow: hidden;
180
+
181
+ }
182
+
183
+
184
+
185
+ .img, .img-2 {
186
+
187
+ position: relative;
188
+
189
+ overflow: hidden;
190
+
191
+ width: 100%;
192
+
193
+ }
194
+
195
+
196
+
197
+ .img img {
198
+
199
+ width: 100%;
200
+
201
+ height: auto;
202
+
203
+ vertical-align: bottom;
204
+
205
+ transition: transform 0.2s linear;
206
+
207
+ -webkit-transition: transform 0.2s linear;
208
+
209
+ }
210
+
211
+
212
+
213
+ .newsB a:hover .img img {
214
+
215
+ transform: scale(1.1,1.1);
216
+
217
+ -webkit-transform: scale(1.1,1.1);
218
+
219
+ }
220
+
221
+
222
+
223
+ .img:after {
224
+
225
+ content: '';
226
+
171
227
  width: 500px;
172
228
 
173
229
  height: 306px;
174
230
 
175
- background-color: lightgreen;
231
+ background: rgb(0,0,0,0.7);
232
+
176
-
233
+ position: absolute;
234
+
235
+ top: 0;
236
+
237
+ left: 0;
238
+
239
+ transition: 0.2s;
240
+
177
- }
241
+ }
178
-
179
-
180
-
242
+
243
+
244
+
181
- .img, .img-2 {
245
+ .newsB a:hover .img:after {
182
-
246
+
183
- position: relative;
247
+ background: rgb(0,0,0,0.3);
184
-
185
- overflow: hidden;
248
+
186
-
187
- width: 100%;
188
-
189
- }
249
+ }
190
-
191
-
192
-
193
- .img img {
250
+
194
-
195
- width: 100%;
251
+
196
-
197
- height: auto;
252
+
198
-
199
- vertical-align: bottom;
200
-
201
- transition: transform 0.2s linear;
202
-
203
- -webkit-transition: transform 0.2s linear;
204
-
205
- }
206
-
207
-
208
-
209
- .newsB a:hover .img img {
253
+ .newsB a:hover .img-box:after {
210
-
211
- transform: scale(1.1,1.1);
212
-
213
- -webkit-transform: scale(1.1,1.1);
214
-
215
- }
216
-
217
-
218
-
219
- .img:after {
220
254
 
221
255
  content: '';
222
256
 
@@ -224,78 +258,14 @@
224
258
 
225
259
  height: 306px;
226
260
 
227
- background: rgb(0,0,0,0.7);
228
-
229
261
  position: absolute;
230
262
 
231
263
  top: 0;
232
264
 
233
265
  left: 0;
234
266
 
235
- transition: 0.2s;
236
-
237
- }
238
-
239
-
240
-
241
- .newsB a:hover .img:after {
242
-
243
- background: rgb(0,0,0,0.3);
244
-
245
- }
246
-
247
-
248
-
249
- .newsB a:hover .img-box:after {
250
-
251
- content: '';
252
-
253
- width: 500px;
254
-
255
- height: 306px;
256
-
257
- position: absolute;
258
-
259
- top: 0;
260
-
261
- left: 0;
262
-
263
267
  background: rgb(0,0,0,0.5);
264
268
 
265
269
  }
266
270
 
267
-
268
-
269
- h3 {
270
-
271
- position: absolute;
272
-
273
- top: 50%;
274
-
275
- left: 50%;
276
-
277
- color: #fff;
278
-
279
- z-index: 1;
280
-
281
- }
282
-
283
-
284
-
285
- .newsB a p:nth-child(2) {
286
-
287
- font-weight: 800;
288
-
289
- }
290
-
291
-
292
-
293
- .newsB a p:last-child {
294
-
295
- overflow: hidden;
296
-
297
- color: #aaa;
298
-
299
- }
300
-
301
271
  ```