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 http://codepen.io/Kuzyo/pen/zhJxH

    # July 9, 2013 at 11:03 am

    Hi!
    http://codepen.io/anon/pen/cqrxm
    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.http://codepen.io/Kuzyo/pen/zhJxH

    # 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 http://jsbin.com/ibufux/3 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.

    http://codepen.io/pannafranka/pen/ipraJ

    # 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.

*May or may not contain any actual "CSS" or "Tricks".