I was trying to create a queue of playing card that is responsive to display width.
I want this queue to be fit to display width so that no card get lost from display. I want to cover conventional width of phone, tablet and desktop.
I also like to align this queue to center so that it does not look bad.
jsfiddle
<div>
<img src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
<img class="rest" src="http://chetart.com/blog/wp-content/uploads/2012/05/playing-card-back.jpg" alt="">
</div>
div{
width:100%;
}
img{
display: inline-block;
height: 200px;
}
.rest{
margin-left: -102px;
}
This is a perfect fit for the new Flexbox model!
Use display:inline-flex
on your wrapping div, and remove the display:inline-block
on img
:
div{
width:100%;
display:inline-flex;
}
img{
height: 200px;
}
.rest{
margin-left: -102px;
/*flex-grow:1;*/ /* Bonus : all available width is occupied */
}
The flex-grow:1
causes your img
to grow, while space is available, but they are deformed.
Here's a demo, and some references and extras :
If you want better browser compatibility, you can do it this way
class="rest"
div{
width:100%;
text-align:center; /* If you want it centered */
padding-right:102px; /* Inverse the value of the card's right margin */
box-sizing:border-box; /* Because we want the padding to be included in the width calculation */
}
img{
display: inline-block;
height: 200px;
}
.rest{
margin-right: -102px; /* Use margin-right instead of margin-left */
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With