2014-03-12 75 views
5

我試圖創建一個響應顯示寬度的紙牌隊列。使用css html的響應式紙牌設計

Queue of card that i like to be responsive

我想這個隊列是適合顯示寬度,使無卡獲得從顯示器丟失。我想涵蓋手機,平板電腦和桌面的傳統寬度。

我也想把這個隊列調整到中心位置,以免看起來不好。

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; 
} 
+0

固定的卡的數量? –

+0

是固定的。 21張牌。 @HashemQolami –

回答

5

這是一個完美的結合爲新Flexbox model

你的包裹格

使用display:inline-flex,並刪除display:inline-blockimg

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,和一些參考和演員:

+0

@Bigood ....你只是節省了一天......這正是我一直在尋找的。非常感謝。 –

+0

@FahadBillah不客氣:) – Bigood

1

如果你想更好的瀏覽器兼容性,你可以做到this way

  • 讓所有的卡都class="rest"
  • 更新你的CSS這個
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 */ 
} 
+0

這也是一個不錯的選擇,但我想保持所有的卡單行。謝謝btw –