简体   繁体   English

当我在html5中填充网格时如何避免空白?

[英]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;
}

This is the fiddle 这是小提琴

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()方法时,需要记住两点:

  1. 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中。

  2. 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.

相关问题 如何在 HTML 中填充网格中的空白空间? - How to fill the empty spaces in the grid in HTML? 如何在空白处填充额外的网格项? - How to fill in extra grid items in empty spaces? 如何发现和填充同位素jquery网格中元素之间的空白空间? - How to discover and fill empty spaces between elements in isotope jquery grid? 在html5中单击画布上的网格时如何填充单元格 - how to fill a cell on clicking the grid on canvas in html5 如何用图像填充html5画布网格正方形? - How to fill html5 canvas grid squares with image? 如何填写空的 html 表空间<td></td>所以我的 JSON 数据排列正确吗? - How do I fill in empty html table spaces with <td></td> so my JSON data lines up properly? 使用历史记录API HTML5时如何避免404 - How avoid 404 when using history API HTML5 当使用angularjs和Bootstrap在HTML5页面的屏幕上单击TAB时,如何从字段输入值中删除空格 - How do I remove spaces from a field input value when TAB is clicked on the screen on a HTML5 page using angularjs and Bootstrap 如何在网格上为HTML5画布创建随机行? - How Do I Create Random Rows For HTML5 Canvas On a Grid? html5 视频标签在没有上传视频时显示一个空的视频框。 我怎样才能隐藏这个空盒子? - html5 video tag displays an empty video box when no video is uploaded. How can I hide this empty box?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM