我試圖渲染HTML table
佈局與css
屬性:對準顯示器列:表
display:table, table-row, table-cell...
下面是我想:
+---------------+---------------------------------------+-----------------+
| my li | a content in a li | another content |
+---------------+---------------------------------------+-----------------+
| my li | a longer content that expend the cell | another content |
+---------------+---------------------------------------+-----------------+
| my li | foo bar foo bar in a li | a content |
+---------------+---------------------------------------+-----------------+
這是什麼我得到了:
+---------------+-------------------+-----------------+
| my li | a content in a li | another content |
+---------------+---------------------------------------+-----------------+
| my li | a longer content that expend the cell | another content |
+---------------+---------------------------------------+-----------------+
| my li | foo bar foo bar in a li | a content in li |
+---------------+-------------------------+-----------------------+
有沒有辦法align列沒有明確設置width
?
下面是代碼:
#container{
display: table;
border: 1px solid orange;
}
#container ul {
display: table-row;
border: 1px solid cyan;
}
#container ul li {
display: table-cell;
border: 1px solid magenta;
vertical-align: middle;
text-align: center;
}
#container ul li:first-child {
text-align: left;
}
<div id="container">
<ul><li>my li</li><li>a content in a li</li><li>another content</li></ul>
<ul><li>my li</li><li>a longer content that expend the cell</li><li>another content</li></ul>
<ul><li>my li</li><li>foo bar foo bar in a li</li><li>a content in li</li></ul>
</div>
看起來對我來說http://jsfiddle.net/Nj7QN/ – SaturnsEye
在哪個瀏覽器中不起作用?對我來說,Chrome可以。 – Guillaume