[英]how to avoid empty spaces when I fill a grid in html5?
how to avoid empty spaces when I fill a grid, I would like to use all the spaces. 如何在填充网格时避免空白,我想使用所有空白。
In this example how can I introduce the div with the number 4 in the space under the div with the plus and avoid the empty spaces in the grid, the div with the number 4 is down and outline of the grid. 在此示例中,如何在加号div下方的空间中引入数字4的div并避免网格中的空白空间,数字4的div向下并显示网格的轮廓。
This is my code: 这是我的代码:
html html
<div id="grid">
<div class="cell2x3" >1</div>
<div class="cell1x1" >+</div>
<div class="cell2x2" >2</div>
<div class="cell1x3" >3</div>
<div class="cell2x1" >4</div>
<div class="cell1x2" >5</div>
</div>
css: CSS:
#grid {
width: 600px;
height: 300px;
outline: 1px solid blue;
}
.cell {
outline: 1px solid red;
float: left;
height: 100px;
width: 100px;
}
.cell2x3 {
outline: 1px solid red;
float: left;
height: 200px;
width: 300px;
}
.cell1x1 {
outline: 1px solid red;
float: left;
height: 100px;
width: 100px;
}
.cell2x2 {
outline: 1px solid red;
float: left;
height: 200px;
width: 200px;
}
.cell1x3 {
outline: 1px solid red;
float: left;
height: 100px;
width: 300px;
}
.cell2x1 {
outline: 1px solid red;
float: left;
height: 200px;
width: 100px;
}
.cell1x2 {
outline: 1px solid red;
float: left;
height: 100px;
width: 200px;
}
You need to clear the float. 您需要清除浮动。 type in
输入
<div style="clear:both"></div>
to remove the float of the the current divs and effectively create a new line. 删除当前div的浮动,并有效地创建新行。
Solution using jQuery: 使用jQuery的解决方案:
1-Take the div element with the number 4 1-以数字4取div元素
var div_4 = $('#grid').children('div').eq(4);
2-Remove div element whit number 4 from the DOM 2从DOM中删除div元素为4的数字
div_4.remove();
3-Add div element whit number 4 after the div with the plus 3-在div后面加div元素加号4
div_4.insertAfter($('#grid').children('div').eq(1));
This can be more optimized. 这可以更优化。
When using the jQuery remove() method, you need to keep two things in mind: 使用jQuery remove()方法时,需要记住两点:
While the elements selected are removed from the DOM using remove() , they have not been removed from the jQuery wrapper set. 尽管使用remove()从DOM中删除了选定的元素,但尚未将它们从jQuery包装器集合中删除。 That means in theory you could continue operating on them and even add them back into the DOM if desired.
从理论上讲,这意味着您可以继续对其进行操作,甚至可以根据需要将其重新添加到DOM中。
This method will not only remove the elements from the DOM, but it will also remove all event handlers and internally cached data that the elements removed might have contained. 此方法不仅将删除DOM中的元素,还将删除所有事件处理程序以及被删除的元素可能包含的内部缓存的数据。
if you want a solution without use jQuery let me know.... 如果您想要不使用jQuery的解决方案,请告诉我...。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.