Get a free trial // Grow your CSS skills // Land your dream job

Need help in generating blocks with for loop

  • # July 9, 2013 at 10:11 am

    Hi guys

    Try to write a little game in JS using jQuery and I have to generate blocks with js can somebody give me advice how I can do it? Thanks for any help. Have to look something like this

    # July 9, 2013 at 11:03 am

    To create new element I used document.createElement method.
    After that should set property className to “bricks”
    end on the end append new element to relevant conteinter, in your case #field div.

    One thing makes me curious. Why the margin of first (not added) elements is bigger than set (1px?)
    Someone know?

    # July 9, 2013 at 11:15 am

    Thanks @Malgosia appreciate your help. I remove **display: inline-block;** and added **float: left:** to .bricks looks better.

    # July 10, 2013 at 7:05 am

    So it wasn’t you want to accomplish, right?
    Maybe, you tell more about your project to help better understand your problem?

    # July 10, 2013 at 3:57 pm

    Thanks, everything fine. Here some result, but game don’t get action yet Do you understand what I’m going to achive?

    # July 12, 2013 at 4:30 am

    Ok, now I know what you want to accomplish :)
    And I think the better solution would be make bricks positioned absolute.
    Because after removing one of them, the rest would be still on the right place.

    See my codepen code. Perhaps you find it interesting and it help you.
    It is also without action function.

    # July 13, 2013 at 9:37 am

    Thanks for the help.

Viewing 7 posts - 1 through 7 (of 7 total)

You must be logged in to reply to this topic.

There's a whole bunch of content on CSS-Tricks.

Search for Stuff   •   Browse the Archives

Get the Newsletter ... or get the RSS feed