2016-12-04 43 views
0

我試圖動態地在div內附加卡片。JQuery追加跳過空格後的內容

我的代碼做如下:

$.getJSON(url, function(jsonresult2) { 


     for (var i = 0; i < 30; i++) { 
      phototemp = link_to_photo; 
      itemname = link_to_item_name; 
      itemcategory = link_to_item_category; 


      $("#populateexplore") 
       .append(' 
         <div class="col-lg-3 col-md-4 col-sm-6" style="float:left"> 
         <div class="card"><img src="' 
         + phototemp 
         + '" style="width:100%;height:200px;"><div class="container"> <h4> <b> ' 
         + itemname 
         + '</b></h4><hr><p>Category:' 
         + itemcategory 
         + '</p></div></div></div>'); 
     } 
    }).error(function() { sweetAlert("Cannot find the place"); }); 

divCSS

.card { 
    box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2); 
    transition: 0.3s; 
    border-radius: 5px; /* 5px rounded corners */ 
    background-color: #CCC; 
    margin-bottom: 10px; 
} 

的問題是,輸出CADS不浮在左側而是給左邊的空白空間

https://i.imgur.com/ols6AVx.jpg

有沒有什麼辦法可以填補左側的空白空間?

+0

如果你正在使用引導網格系統,那麼爲什麼你添加(浮動:左)網格系統已經擁有它。 –

+0

@yahya 刪除它不會影響輸出。它仍然向右。 我只是給它一個試試:) – Pujan

+0

我不能確定,因爲我沒有完整的代碼,或者如果你可以給網站鏈接,可能有所幫助.. –

回答

1

看起來第三張卡的高度比其他卡高,它阻止了第五張卡向左側漂浮。嘗試調整卡的大小,使其具有相同的高度,並查看是否可以解決問題。

+0

使每張卡相同的高度確定它,但每張卡內的內容都不相同。所以有些文本如果長時間就會從卡中刪除 – Pujan