1
我有一個父div與七個或更多的孩子divs內。我需要在...之間顯示4個子div,其餘的將在隨後的四個div各行中進行換行。我需要所有的子div都具有相同的高度,相對於共享同一行的其他三個子div。父div也具有響應性,所以當視口較小時,它最終可能會顯示2個子div的行。與同等高度和包裝的兒童div
display:inline-block不能解決此問題(不等於子div高度),並且display:table-cell不允許子div包裝到後續行中。我怎樣才能實現我的目標?
這是一個非常基本的jfiddle:https://jsfiddle.net/hockey2112/3r2pL25v/
<div class="table">
<div class="tablecell">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="tablecell">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. This div has a little more information in it, and therefore it will be taller than the other divs.</div>
<div class="tablecell">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="tablecell">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="tablecell">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="tablecell">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
<div class="tablecell">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.</div>
</div>
.table {font-size: 9px;}
.tablecell {display: inline-block;
width: 23%; border: 1px solid #ff0000; vertical-align: top;}
您應該使用[Flexbox的(https://css-tricks.com/snippets/css/a-guide-to-那麼Flexbox /)。 – alesc
完美無缺!這是更新的jfiddle:https://jsfiddle.net/hockey2112/vbubpha4/。你可以請你的評論作爲答案,我可以接受嗎?謝謝! – hockey2112