內的div的數值N是有辦法來定位一個div容器內的div N多,因此使用CSS和JS每個格單元不會相互碰撞。 我們需要在不改變高度和頂部值的情況下設置左側值。可以改變單元格寬度。有沒有一種方法來定位的div容器
請檢查該代碼示例。
.container
\t {
\t width : 400px;
\t height : 1000px;
\t background : #000;
\t position : relative;
\t }
\t .cell
\t {
\t position :absolute;
\t background : yellow;
\t border: 2px solid red;
\t }
<div class="container">
<div class="cell" style="top:50px;width:100%;height:100px"></div>
<div class="cell" style="top:150px;width:50%;height:50px"></div>
<div class="cell" style="top:150px;width:50%;height:50px;"></div>
<div class="cell" style="top:230px;width:33.33%;height:50px;"></div>
<div class="cell" style="top:230px;width:33.33%;height:50px;"></div>
<div class="cell" style="top:230px;width:33.33%;height:50px;"></div>
</div>
預期輸出:
你期待什麼輸出? –
「位置:絕對」必要嗎? – Swellar
提供至少你所期望的輸出,使我們也許能夠想象它更好 – Swellar