【发布时间】:2011-04-03 05:28:04
【问题描述】:
我正在尝试在布局中制作图案(请参阅附件进行可视化) 问题是使用 :odd :even 不起作用。
我试图通过使用“for 循环”和 if 语句来使其工作,但显然 jquery 不会以这种方式做这些事情。或者也许我应该在文档准备声明之外做它?我厌倦了它,但它不起作用。
如何做到这一点?
编辑:重要提示... 这些方块在一页上最多 8 个,并在 Wordpress 中生成,每个方块都是一个帖子。所以不幸的是,我无法按照建议将事物分成几行。
css:
.thumb_container {
width:274px;
height: 274px;
float: left;
position: relative;
background-color: white;
}
.thumb_container:nth-child(4n+1) { clear:both; background-color: green } /* green just to see if its working */
jQuery tweek 文件 (http://baked-beans.tv/bb/wp-content/themes/bakedbeans/js/jquery.site.tweeks.js)
$(".thumb_container:nth-child(8n+2), .thumb_container:nth-child(8n+4), .thumb_container:nth-child(8n+5), .thumb_container:nth-child(8n+7)")
.css({"background-color":"#333333"});
HTML点击HTML链接
【问题讨论】:
-
显示您的
.thumb_container元素 (HTML)。此外,您的代码实际上每次都会更改所有元素的样式。
标签: jquery css layout grid for-loop