|
Posted by meltedown on 12/26/05 21:18
Sunil wrote:
> could any body can help me in HTML/CSS
>
> i have one div and its width and height is 200px; and one child div its
> height and width is 50px;
> now i want that child div in center of the parent div. child div could
> be more than one may be 5. all should be center aligned and inlined.
> can any body help me pls :)
>
http://www.reenie.org/test/test24.php
Just fill in the input and look at the source.
If you want the algorithm, here is the php function.
$cells is an array of the content.
function
centercells($cells,$parentwidth=200,$parentheight=200,$cellwidth=50,$cellheight=50,
$cellpadding=1, $cellmargin=1,$cellborder=1){
$numcells=sizeof($cells);
$extspace=($cellpadding+$cellmargin+$cellborder)*2;
foreach($cells as $cell)
$r.="<div style=\""."width:$cellwidth"."px;
height:$cellheight"."px; margin:$cellmargin"."px;border:solid
$cellborder"."px;padding:$cellpadding"."px;float:left;text-align:left;\">$cell</div>";
$onewidth=$cellwidth+$extspace;
$oneheight=$cellheight+$extspace;
$maxcols=floor($parentwidth/$onewidth);
if($maxcols > $numcells)$cols=$numcells;else $cols=$maxcols;
$rowsext=fmod($numcells,$cols);
$rows=floor($numcells/$cols);
if($rowsext)$rows++;
$colheight=$oneheight*$rows;
$topmargin=($parentheight-$colheight)/2;
$width=$cols*$onewidth;
$width+=1;// neccesary for internet explorer
$width.='px';
$r="<div style=\""."width:$width;margin:$topmargin"."px
auto;\">$r</div>";
$r="<div
style=\""."width:$parentwidth"."px;height:$parentheight"."px;border:solid
1px;text-align:center;\">$r</div>";
return $r;
}
[Back to original message]
|