简体   繁体   English

将div划分为方块

[英]Dividing the div into square blocks

我有一个覆盖整个屏幕的div现在我想在这个div中动态生成方形Div,就像数学笔记本一样,为每个方块提供替代颜色

I can't give you too much because I don't know what you've tried and what specific problems you've encountered, but this'd be the basic idea: 我不能给你太多,因为我不知道你尝试了什么以及你遇到了哪些具体问题,但这是基本的想法:

for(var i = 0; i < 1000; i++) {
    var block = $('<div class="block" />');
    block.addClass('block-' + ((i%2)+1));

    $('body').append(block);
}

Have your .block div's float left, and set to the size you want them to be, and they'll automatically wrap to the next row. .block div的浮动向左移动,并设置为您希望它们的大小,它们将自动换行到下一行。 They'll also have either the class .block-1 or .block-2 , which you can use to set the alternating colors. 它们还将具有.block-1.block-2 ,您可以使用它们来设置交替的颜色。

Of course, if a background image, as has been suggested in comments, would meet your needs, than that would perform heaps better :) 当然,如果像评论中所建议的那样,背景图像能够满足您的需求,那将比堆表现更好:)

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

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