r/csshelp • • Aug 08 '20

This gap is driving me crazy!

I have cards that I'm placing in a grid layout. Each card is actually a column flexbox with an image on top and a h3 on bottom. The image is a fixed size. Each card should only take the size of its children.

Using chrome devtools, I can see there is a gap between the h3 and its padding and the image above, but I can't tell what its from and I can't get rid of it. I also checked another browser and its the same.

https://codepen.io/jstocks/pen/JjXdjbw

I'm quite new to CSS. If there is a better place to ask this, let me know please.

9 Upvotes

4 comments sorted by

3

u/RedDragonWebDesign Aug 08 '20

I was surprised when I went into your CodePen and I didn't see flex used on the card. That is the approach I would take.

display: flex;
flex-direction: column;

Here's a JS Fiddle with the gap fixed.

3

u/stoxnbonds Aug 08 '20

That worked perfectly of course. Thank you!

For educational purposes, you have any idea where that gap comes from?

There's no margin/padding on the image and no margin/padding on the h3. And the card is not a fixed size except for the width from being a grid item.

If not, thank you again!

4

u/[deleted] Aug 08 '20 edited Aug 08 '20
display: inline;

(which is the standard when undefined) creates this gap after the img

display: block;

will also remove the gap aswell (when added to the img-CSS of course), but the solution above is better than this approach

1

u/stoxnbonds Aug 08 '20

ahhh. Ok. Thank you!