根据需要并排安排DIV - HTML PHP

I have been goggling this for a while to set one of my requirement. This is what my detailed flow of page.

I have below page and want to arrange DIV in this fashion. Each of this DIV will be filled from my DB. If i have only three item in the DB, then the page should show first row with only three divs and so on. How can i do this by using HTML 5 , CSS and PHP?


  ...........      ..............         ...............            ..............
  .         .      .            .         .             .            .            .
  .   Div1  .      .   Div2     .         .   Div3      .            .   Div4     .
  .         .      .            .         .             .            .            .
  .         .      .            .         .             .            .            .
  .         .      .            .         .             .            .            .


  ...........
  .         .
  .  Div5   .    
  .         .
  .         .
  .         .

You can create a counter and set a line break for every 4 divs listed for example, or you can set a maximum width for the parent div, so they will "break" automatically when it does not fit anymore (do not think this cool idea).

You need to assign the parent container a fixed width. Then probably assign the divs some set width and position them relative to the first one.Also set float:left; to all of the divs using css. This should get you working.