Need solution

Discussion in 'HTML' started by Sunil, Dec 26, 2005.

  1. Sunil

    Sunil Guest

    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 :)
     
    Sunil, Dec 26, 2005
    #1
    1. Advertising

  2. 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 :)
    >


    Do you mean up to (5) 50px squares stacked vertically within (1) 200px
    square? If so, math will be your enemy, 50x5=250, what are you going to
    do with the overflow? Also, with compliant browsers if you specify
    border, padding, and margin for the child DIVs, that will also be added
    to the total!

    --
    Take care,

    Jonathan
    -------------------
    LITTLE WORKS STUDIO
    http://www.LittleWorksStudio.com
     
    Jonathan N. Little, Dec 26, 2005
    #2
    1. Advertising

  3. Sunil

    meltedown Guest

    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;
    }
     
    meltedown, Dec 26, 2005
    #3
  4. Sunil

    Sunil Guest

    Thanks Jonathan

    actually the parent Div's width is 800px; and child div's width is
    50px; and it can't be more than 5. and i want all 5 child divs in
    center of the parent div.

    1. child div could 1 or 2 or 3 or 4 or 5.
    2. the all child divs should be inline.

    waiting for you reply.

    thanks in advance.


    Jonathan N. Little wrote:
    > 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 :)
    > >

    >
    > Do you mean up to (5) 50px squares stacked vertically within (1) 200px
    > square? If so, math will be your enemy, 50x5=250, what are you going to
    > do with the overflow? Also, with compliant browsers if you specify
    > border, padding, and margin for the child DIVs, that will also be added
    > to the total!
    >
    > --
    > Take care,
    >
    > Jonathan
    > -------------------
    > LITTLE WORKS STUDIO
    > http://www.LittleWorksStudio.com
     
    Sunil, Dec 27, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Francis
    Replies:
    0
    Views:
    451
    Andrew Francis
    Jun 28, 2006
  2. =?Utf-8?B?Y2FzaGRlc2ttYWM=?=

    Solution file not in the solution folder

    =?Utf-8?B?Y2FzaGRlc2ttYWM=?=, Sep 12, 2006, in forum: ASP .Net
    Replies:
    2
    Views:
    1,154
    Laurent Bugnion
    Sep 12, 2006
  3. , India
    Replies:
    17
    Views:
    1,142
    James Kanze
    Oct 1, 2007
  4. Replies:
    8
    Views:
    544
  5. email55555 email55555

    [SOLUTION] Ruby Quiz #14 LCD Numbers ( solution #2 )

    email55555 email55555, Jan 9, 2005, in forum: Ruby
    Replies:
    16
    Views:
    308
    David Tran
    Jan 10, 2005
Loading...

Share This Page