我想顯示一個複雜但固定大小的多行元素列表,假設它們將在行結束時覆蓋頁面行,使它們在每行中出現n
,當 n
取決於頁面寬度。例如:多行跨度行爲元素
Mary had Mary had Mary had
a little a little a little
LAMB LAMP WHISKEY
Mary had
a little
TOO MUCH
我應該怎麼做?
我想顯示一個複雜但固定大小的多行元素列表,假設它們將在行結束時覆蓋頁面行,使它們在每行中出現n
,當 n
取決於頁面寬度。例如:多行跨度行爲元素
Mary had Mary had Mary had
a little a little a little
LAMB LAMP WHISKEY
Mary had
a little
TOO MUCH
我應該怎麼做?
inline-block
跨度應該這樣做:
body {
font-family: sans-serif;
}
#container span {
display: inline-block;
width: 5em;
border: 1px solid black;
}
<div id='container'>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
<span>Mary had a little lamb</span>
</div>
</body>
</html>
使用組合display: block;
float:left;
和您想要的width
和height
。
span {
display: block;
float: left;
height: 100px;
width: 100px;
}
花車只是爲我做了太多奇怪的事情。 :-) – 2010-03-09 15:33:29
@ T.J。是的,我可以涉及到,我不知道內聯塊在IE6工作,雖然;-) – 2010-03-09 15:47:05
只是*勉強* ;-) – 2010-03-09 15:58:07
應該指出的是,內聯塊在IE6中不起作用: ) – 2010-03-09 15:29:24
@Andy E:實際上,它確實 - 但IE6只允許你在通常默認爲'inline'的元素上設置'inline-block',而不是通常默認爲'block'的元素。我記得那個例子,所以我現在已經解決了。 :-) – 2010-03-09 15:32:29
@ T.J。好的! :-) – 2010-03-09 15:39:14