简体   繁体   English

流畅的CSS网格结构可能吗?

[英]Fluid CSS Grid structure possible?

Short and simple version: I have a project where I need to define a DIV that will repeat horizontally and then wrap to the next row when out of space (tabular-like grid). 简短的版本:我有一个项目,我需要定义一个DIV,该DIV将水平重复,然后在空间不足时(表格状网格)包装到下一行。 I've seen mention of jQuery.GridLayout, but the demo/homepage is 404'd so I have no clue if this is what I'm looking for. 我已经提到了jQuery.GridLayout,但是演示/主页是404,所以我不知道这是否是我想要的。 Simply, I'm trying to achieve this: 简单来说,我正在努力实现这一目标:

Div.ItemClass   Div.ItemClass   Div.ItemClass   Div.ItemClass
Div.ItemClass   Div.ItemClass   Div.ItemClass   Div.ItemClass
...

The trick is that I'm forced to use the same class (I do have access to an Alternate Item template that will insert different code for each alternate item) but I need them to 'stack' horizontally until they run out of horizontal space and then 'wrap' to the next row. 诀窍是我被迫使用相同的类(我确实可以访问替代项目模板,该模板将为每个替代项目插入不同的代码),但是我需要它们水平地“堆叠”,直到它们用完水平空间并然后“包装”到下一行。

Quick background - the project is inside a CMS system, and the item listing module gives me the following template files to work with inside the "list" view: 快速背景-该项目位于CMS系统内部,项目列表模块为我提供了以下模板文件,可在“列表”视图中使用这些模板文件:

-Header
-Item
-Alternate Item
-Footer

Thoughts, ideas? 有想法,想法吗?

Edit: ok, so I'm a bit of an idiot and forgot rule #1 - Check your (rendered) source. 编辑:好的,所以我有点白痴,忘记了规则#1-检查您的(渲染)源。 The most significant problem is that the CMS Module that is being used is 'wrapping' each template object (Header, Item, alternate, footer) inside a TD element, making a true 'wrapping div' nigh impossible. 最重要的问题是,正在使用的CMS模块正在“包装” TD元素内的每个模板对象(页眉,项目,备用项,页脚),几乎不可能实现真正的“包装div”。 I'm glad I wasn't just going nuts because I was fairly certain nested DIVs were the right approach. 我很高兴自己不仅发疯,因为我确信嵌套DIV是正确的方法。

Edit #2: Ok, now I'm thinking that I can maybe pull this off with a bit of jQuery manipulation. 编辑#2:好的,现在我正在考虑可以通过一些jQuery操作来实现这一点。 I would need to target the Div.ItemClass and then place them inside the positioned wrapper div, possibly overlaying / replacing the exising tabular layout code (maybe used in the Header template?). 我需要定位到Div.ItemClass,然后将它们放置在定位的包装div中,可能会覆盖/替换现有的表格布局代码(可能在Header模板中使用?)。 As of this edit the current code that is forced when rendered is: 从此编辑起,渲染时强制执行的当前代码为:

<td><!--This is Header.html --><div class="Container" /></td>
<td><!--This is Item.html --><div class="ItemName">Item 1</div></td>
<td><!--This is Alternate.html --><div class="ItemName">Item 2</div></td>
<td><!--This is Item.html --><div class="ItemName">Item 3</div></td>
<td><!--This is Footer.html -->[PAGER]</td>

I hope this makes sense, as I've stated earlier, alot of the tables are forced by the CMS and module system I'm having to use for this project. 我希望这是有道理的,正如我之前所说的,很多表是由我必须用于该项目的CMS和模块系统所强制的。

Edit #3 - Managed to make it work! 编辑#3-设法使其工作! Added a bit of jQuery: 添加了一些jQuery:

$(function() {
    $('div.ItemClass').appendTo('#ContainerID');
});

Simply, it grabs the Divs out of the TD elements and places them in the ContainerID I placed in the Header.html section! 简而言之,它将Divs从TD元素中提取出来并将它们放在我在Header.html部分中放置的ContainerID中!

If you have fixed widths it's easy. 如果宽度固定,这很容易。 Just put float lefts on them and arrange the width accordingly so that only X items will be on a row. 只需在其上放置左浮动并相应地设置宽度,以使只有X个项目排在一行上。 Something like 就像是

<div class="container">
  <div class="item">lorem ipsum</div>
  <div class="item">lorem ipsum</div>
  <div class="item">lorem ipsum</div>
  <div class="item">lorem ipsum</div>
  <div class="item">lorem ipsum</div>
  <div class="item">lorem ipsum</div>
  <div style="clear: both;"></div> <!-- just to fix the height, remove to see effect. -->
</div>

and style 和风格

.container {
   width: 500px;
}
.item {
   width: 100px; // for 5 items (without margins)
   float: left;
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM