Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums CSS Help auto padding and centering divs Re: Help auto padding and centering divs

#77352
luxurychair
Member

The problem is that he wants the divs equally spaced in their parent container (if I’m reading the question correctly). Because you can’t do math in CSS (dividing the total space by the number of elements) you can’t adjust for a differing number of elements.

It would be possible though to do the math in PHP before hand if PHP knows how many elements there are. The math would be very similar to the math shown in the jQuery example above but you would just add the widths to a style="" attribute or make a custom CSS class for the inner divs which changes based on how many there are. "DivWith3Siblings", "DivWith5Siblings", etc with each of the CSS classes having a different amount of padding.