div 方格,float:left 问题(包括图片)

2023-08-01前端开发问题
29

本文介绍了div 方格,float:left 问题(包括图片)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

问题描述

我正在尝试制作一个网格,使其整体尺寸始终相同 (800x600).

i am trying to make a grid in such a way that it is always the same size overall (800x600).

但是,我不希望网格中的所有正方形都具有相同的大小.

however, i do not want all squares in a grid to be of the same size.

正如你所看到的,只要我增大一个正方形(2x2+间隙 - 图像中的彩色银色),所有其余较小的正方形都不会重新对齐,而是从下一行的开头开始 - 创建一个白色间隙在第二行.

as you can see as soon as i make one square bigger (2x2+gap - colored silver in the image) all the rest of the smaller squares do not realign and start from the start of the next row - creating a WHITE gap in row two.

有没有办法解决这个问题?

is there a way to fix this?

这是他们的 CSS:

.squareTEST1, .squareTEST2
{
    width: 60px;
    height: 60px;
    margin: 3px;
    float: left;
}

.squareTEST1A
{
    width: 126px;
    height: 126px;
    margin: 3px;
    float: left;

    background-color: Silver;
}

.squareTEST1
{
    background-color: Red;
}

.squareTEST2
{
    background-color: Blue;
}

非常感谢任何帮助编辑在这里试试:http://jsfiddle.net/NF9N9/

thnx a lot for any assistance edit try it here: http://jsfiddle.net/NF9N9/

注意:可能还有其他不同大小的正方形 3x3 和 4x4,但大多数是 1x1 的.只想制作一个没有缝隙的完美网格.它必须是动态的,这意味着任何正方形都可以在任何位置被炸毁,但最终它应该是一个紧凑的网格.

note: there may be other squares of different sizes 3x3 and 4x4, but the majority will be the 1x1 ones. just want to make a perfect grid with no gaps. it has to by dynamic, meaning any square can be blown up in any position, but in the end it should end up a compact grid.

--

不相关 (LOW PRIO) - 但如果有人知道将 800x600 网格划分为 12 列 9 行(-1 或 2 行或列 - 我可以接受稍大的正方形)的更好方法,最终为 800x600 和有可被 5 整除的间隙和大小,我将不胜感激:P

推荐答案

遗憾的是,您不能仅使用 css 浮点数来做到这一点.我知道您最初是在寻找纯 CSS 的解决方案,但我认为去这里的唯一方法是使用 jQuery Masonry 之类的东西:http://masonry.desandro.com/

Sadly you can't do this with css floats only. I know you were initially looking for a css-only solution, but I think the only way to go here is to use something like jQuery Masonry : http://masonry.desandro.com/

这篇关于div 方格,float:left 问题(包括图片)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

The End

相关推荐

layui 单选框、复选框、下拉菜单不显示问题如何解决?
1. 如果是ajax嵌套了 页面, 请确保 只有最外层的页面引入了layui.css 和 layui.js ,内层页面 切记不要再次引入 2. 具体代码如下 layui.use(['form', 'upload'], function(){ var form = layui.form; form.render(); // 加入这一句});...
2024-11-09 前端开发问题
313

layui tree树组件怎么自定义添加图标
经常用到layui的朋友都知道,layui tree默认是不能自定义图标的,那么我们要自定义的话要怎么操作呢? 首先用编辑器软件(修改时候用编辑器记得编码),打开layui.js。搜索: i class="layui-icon layui-icon-file" 改为如下代码: i class="'+ (i.icon || "l...
2024-10-26 前端开发问题
493

layui要如何改变时间日历布局大小?
问题描述 我想改变layui时间日历布局大小,这个要怎么操作呢? 解决办法 可以用css样式对时间日历进行重新布局,具体代码如下: !DOCTYPE htmlhtmlheadmeta charset="UTF-8"title/titlelink rel="stylesheet" href="../../layui/css/layui.css" /style#test-...
2024-10-24 前端开发问题
271

CoffeeScript 总是以匿名函数返回
CoffeeScript always returns in anonymous function(CoffeeScript 总是以匿名函数返回)...
2024-04-20 前端开发问题
13

getFullYear 在一年的第一天返回前一年
getFullYear returns year before on first day of year(getFullYear 在一年的第一天返回前一年)...
2024-04-20 前端开发问题
6

如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?
How do I make a TextGeometry multiline? How do I put it inside a square so it wraps like html text does inside a div?(如何制作 TextGeometry 多线?如何将它放在一个正方形内,以便它像 html 文本一样包裹在 div 内?) - IT屋-程序员软件开发技术分享社...
2024-04-20 前端开发问题
6