I have a simple set of cards that show side-by-side images, which I need to be responsive to screen width. So using simple inline-block
, I have this structure:
<div class="cards" id="ex1">
<div class="card">
<img src="http://www.clker.com/cliparts/5/b/a/7/1194986784455829849basebalm_ganson.svg.med.png" />
</div>
<div class="card">
<img src="http://www.clker.com/cliparts/d/1/4/6/11971185311926706097Gioppino_Basketball.svg.med.png" />
</div>
</div>
With this CSS:
.cards {
display: inline-block;
border: 2px solid #808080;
border-radius: 2px;
padding: 10px;
margin-bottom: 20px;
}
#ex1 .card {
width: 35%;
display: inline-block;
}
But to my surprise, the parent div, .cards
, spans the width of the page as if it were display: block
:
However, if I hard-code the widths of the .card
divs, it works as expected. Here's a fiddle that compares the two.
Why does inline-block
not respect percentages that don't add up to 100%? Is there any way to do this with percentages? (I could make them both 50%, but even with box-sizing: border-box
this can cause them to stack vertically.)