我试图创建一个响应显示宽度的扑克牌队列。
我希望此队列适合显示宽度,以免卡片因显示而丢失。我想覆盖手机,平板电脑和台式机的传统宽度。
我也想把这个队列对齐到中心,这样看起来不会很糟糕。
<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;
}
答案 0 :(得分:6)
这非常适合新Flexbox model!
在包装div上使用display:inline-flex
,然后移除display:inline-block
上的img
:
div{
width:100%;
display:inline-flex;
}
img{
height: 200px;
}
.rest{
margin-left: -102px;
/*flex-grow:1;*/ /* Bonus : all available width is occupied */
}
flex-grow:1
导致img
增长,空间可用,但会变形。
这是一个demo,以及一些参考和附加内容:
答案 1 :(得分:1)
如果您想要更好的浏览器兼容性,可以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 */
}