我不確定這是可能的。瀏覽器確定在哪裏打破內容,並且通過CSS無法在這些點上插入內容。我能夠想到的最接近的東西是使用column-break-before:屬性(-webkit-column-break-before,-moz-column-break-before,column-break-before)。
例如:
CSS:
div#multicolumnElement {
-webkit-column-count: 4;
-moz-column-count: 4;
column-count: 4;
}
.special {
-webkit-column-break-before:always;
-moz-column-break-before:always;
column-break-before:always;
}
HTML:
<div id="multicolumnElement">
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Curabitur mattis, lectus
nec tempor auctor, urna urna venenatis nisi, ac pellentesque est felis egestas lorem!
Duis lectus dui, commodo in varius sed, bibendum at eros. Donec ultricies, est quis
pretium porttitor, neque arcu auctor dui, sit amet adipiscing erat est id massa.
Morbi at elementum <img class="special" src="http://dummyimage.com/200x150/000/fff" />lectus. Donec fermentum massa sit amet nisi tempus sed vestibulum
tortor pellentesque. Aliquam dictum, sapien a luctus ultricies, ipsum erat dignissim
tellus, in ultricies mi lorem tempor velit. Vivamus ornare nulla sed arcu elementum
pharetra. </p>
<p>Phasellus cursus felis sed felis porta tempor. Vestibulum at eleifend ligula.
Vestibulum hendrerit ligula at elit lacinia at ultricies metus fringilla! Vestibulum
ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia Curae; Morbi
ultrices tortor vel ipsum imperdiet imperdiet. Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi
eu leo quis lectus aliquet elementum. Aenean porta interdum nibh id posuere? Phasellus
nisl lorem, semper bibendum semper at, malesuada non odio. </p>
<p>In ullamcorper eros quis nisi pharetra tincidunt. Vestibulum ac elit nunc, sed
laoreet leo! Duis et nulla sit amet lorem gravida lacinia. Cras massa ipsum, semper
in mattis ut, fringilla in nisi. Nulla mauris urna, feugiat sed convallis id, facilisis
et sem. Donec egestas ultricies commodo. Aliquam eget nulla enim, et dictum nisi.
In faucibus, leo vitae congue convallis, elit eros venenatis leo, nec lobortis sapien
orci at nunc. </p>
</div>
這在第二塔的頂部產生文本的四列與圖像,然而,取決於文本的數量和可用空間,這可能不會總是按照你的想法。
我會鏈接到一個jsFiddle的例子,但它似乎是關閉ATM。
我假設需求是動態創建列?所以你不能只浮動3個div來模擬多列? – flynfish 2012-02-08 18:35:40
我可以做到這一點,但文字是動態的,我無法確定它的大小。它必須從代碼完成。你認爲這有可能嗎? – 2012-02-08 18:36:50
你可以嘗試使用這個[jquery columnizer plugin](http://welcome.totheinter.net/columnizer-jquery-plugin/),然後將你的圖像添加到第二列。這可以工作,因爲插件將文本分成div。 – flynfish 2012-02-08 19:16:02