I'm trying to make a div float to the center of it's container div, but the thing is that the user may decide to add from 1 up to 12 elements, so they must float in lines of 4. So, if the user adds only one element, this should float to the center of the container, if he/she adds two, they must float to the center of the container but next to each other. If the User adds 5 elements, the first four must float side by side (filling the width 100% of the container) and the fifth should be on the second line, at the center. This images show what I want to achieve:
User input: only one box that floats to center.
The user selected two elements, so both of them float side of each other and to the center of the container div.
The user selected four elements, so the first side is full, the 100% of the container div is filled by four boxes of 25% with each.
If the user selects 5 elements, the fifth one shall float to the center of the container div, right below the first line of the other 4 boxes.
So, at the end, I'll be adding some asp.net vb that will bring the desired boxes to a repeater control, according to some data stored in a SQL database, and bringing the desired controls through a stored procedure.
I've been trying different techniques, but none of them have solved my issue (margin: 0 auto; display: inline-block; etc...)
Any help will be highly appreciated!!
Thanks