我是一個老學校的桌子的傢伙,當談到現代的HTML時,我感到非常困惑。我正在嘗試一些簡單的垂直/水平佈局(即Flex的hbox/vbox),但我們在複製它們時遇到了很大困難。模仿一個HBox/VBox與CSS
一張舊桌子會是這個樣子了與HBox:
<table width="100%" height="100">
<tr valign="middle">
<td nowrap style="background-color:#CCC">I am text on grey</td>
<td width="50%" valign="top">displays top</td>
<td width="50%" align="right">Autosize Fill (displays bottom right)</td>
</tr>
</table>
現在,我試圖用div的做到這一點,但都無濟於事。當使用display:inline時,我無法設置百分比寬度 - 它只需要顯式寬度。當使用float:left時,設置100%的百分比寬度會使其真正達到100%,並向下推動下一個div。
這是我一直在玩代碼:
<html>
<head>
</head>
<style type="text/css">
div.test { background-color: #EE9; padding:5px;}
body { font-family: Arial; }
ul {
list-style-type:none;
}
ul li {
float:left;
}
.hboxinline div {
display: inline;
}
.hboxfloat div {
float:left;
}
.cellA {
background-color:#CCC;
width:100%;
}
.cellB {
background-color:#DDD;
min-width:100;
}
.cellC {
background-color:#EEE;
min-width:200;
}
</style>
<body>
A = 100%, b = 100, c = 200
<div class="test">old school table
<table cellpadding="0" cellspacing="0">
<tr>
<td class="cellA">A</td>
<td class="cellB">B</td>
<td class="cellC">C</td>
</tr>
</table></div>
<br/>
<div class="test">
float:left
<div class="hboxinline">
<div class="cellA">A</div>
<div class="cellB">B</div>
<div class="cellC">C</div>
</div>
</div>
<br/>
<div class="test">ul/li
<ul class="ulli">
<li class="cellA">A</li>
<li class="cellB">B</li>
<li class="cellC">C</li>
</ul>
</div>
<br/>
<div class="test">
display:inline
<div class="hboxfloat">
<div class="cellA">A</div>
<div class="cellB">B</div>
<div class="cellC">C</div>
</div>
</div>
</body>
</html>
因爲這個線程:http://stackoverflow.com/questions/83073/why-not-use-tables-for-layout -in-html 我試圖弄清楚如何爲後代着想「現代」... – ansiart 2010-06-02 20:26:42
哎呀,我沒有看到你已經把東西放進去了。目前爲止在Chrome中運行良好,將測試其他.... 謝謝! – ansiart 2010-06-02 20:29:37
嗯,即不喜歡它 - 但它看起來好像其他所有事情....標記回答 – ansiart 2010-06-02 20:31:08