我有一个宽度为200px,高度为500px的主分区。根据一些事件,我需要在主要部门中添加宽度为50px和高度为50px的子部分。我需要将它从左上方添加到下方并向右流动。从上到下对齐div,然后从左到右
|---------------|
| | |
| 1 | 4 |
|-------|-------|
| | |
| 2 | 5 |
|-------|-------|
| | |
| 3 | 6 |
|-------|-------|
我试过这些CSS,但它不工作。
.SubDiv {
height: 50px;
width: 50px;
background: red;
}
.MainDiv {
max-height: 200px;
height: 200px;
width: 200px;
background: blue;
min-width: 100px;
direction: inherit;
}
<div>
<div id="SimulationPage">
<div id = "ParentDiv" class="MainDiv">
</div>
</div>
<input type='button' id = "adddiv" value='add div' />
</div>
$(document).ready(function() {
$('#adddiv').bind('click', function (eventargs) {
$("#ParentDiv").append('<div class="SubDiv"> </div>');
});
});
有人可以帮助我实现我想要的。
你正在寻找一个纯CSS解决方案还是jQuery + CSS?如果用户添加(1)两个块(2)三个块(3)四个块...两个50px不能填充200px宽的框,则元素如何排列。 –
你不能使用表吗? – sp00m
@SalmanA:我正在寻找唯一的CSS解决方案 –