さまざまなコンテンツが左に浮かんでいるアイテムのリストがあり、それらを行として表示する必要があります。
<ul>
<li>small content..</li>
<li>medium Content..</li>
<li>large content..</li>
..
<!-- many item random contnet -->
</ul>
リスト項目を一列に並べて表示したいと思います。
行の高さは、行のアイテムの最大高さに依存します。取得方法は?
display:table-cell
テーブル列として機能するように追加します。同様に削除float:left
します。
#contentpane{}
#contentpane li{
padding:10px;
width:80px;
border:1px solid #000;
display:table-cell
}
ケース 2
自動高さでそれが必要な場合は、以下のwhite-space:nowrap;
方法を使用してください
ul#contentpane{
width:100%;
white-space:nowrap;
}
#contentpane li{
padding:10px;
width:80px;
border:1px solid #000;
height:auto;
display:inline-block;
white-space:normal !important;
}
デモ 2 || デモ (上に垂直に配置)
clear:both を行オーバーフロー要素に設定するには、javascript を使用する必要があります。
var ch=$("#container").width();
var itemsPerRow=Math.floor(ch/102);
var itemsCount=$("#contentpane li").length;
var loopRound=Math.floor(itemsCount/itemsPerRow);
for(var i=1;i<loopRound+1;i++)
{
var nextFirstItem=i*itemsPerRow+1;
$("#contentpane li:nth-child("+ nextFirstItem +")").css({"clear":"both"});
}
ul {
display: table-row;
}
ul > li {
display: table-cell;
}
display: table
完全なテーブル表現を構築するには、ラッパーが必要であることに注意してください。
高さを li に設定します。
#contentpane{
}
#contentpane li{
float:left;
padding:10px;
width:80px;
height:180px;
overflow:auto;
display:table-cell;
border:1px solid #000;
}
これを試してみてください
var maxHeight = 0;
$("#contentpane li").each(function( index ) {
var height = $(this).height();
if(height > maxHeight){
maxHeight =height;
}
});
$("#contentpane li").css("height",maxHeight);