Page 1 of 1
Dynamic css
Posted: Thu Jul 23, 2009 4:21 pm
by Todlerone
Hello everyone and thank-you in advance for any help/suggestions. Could anyone give me some possible suggestions as to how to make a div height change based on the number of times through a loop. By this I mean if I go once through the loop make the div height 20px, if twice make the height 20*2, and so on. I don't want to make the div 100px when sometimes I have one row of text and at other times I would need 120px. I was also hoping to determine that if it gets to greater than 4 times through the loop an autoscroll could be added to the css. I need to setup the div prior to the loop so would I put limited info in the css of the div and adjust it on the fly. Sorry if I'm alittle vague I have never attempted dynamic css before.
TY kindly
Re: Dynamic css
Posted: Thu Jul 23, 2009 4:40 pm
by andyhoneycutt
I think you could approach this by using javascript, or publishing the div after you've gathered your results from the loop and performed all calculations. Here's a quick example:
Code: Select all
$i = 0;
$auto_scroll = false;
$div_height = 0;
$div_height_scale = 20;
while($item = getItemFromSomewhere())
{
$i++;
$text_to_write .= $item . "<br />\n";
}
$auto_scroll = ($i > 4) ? "auto_scroll_style_stuff_here" : ''; // not sure the css for auto-scroll.
$div_height = $i * $div_height_scale;
echo "<div class=\"some_class\" id=\"some_id\" style=\"height:$div_height;$auto_scroll\">\n";
echo $text_to_write;
echo "</div>";
Hope this helps!
-Andy
Re: Dynamic css
Posted: Thu Jul 23, 2009 10:06 pm
by Todlerone
TY very very much Andy. I'm not familiar with javascript so I will try to integrate it with my current code.
Cheers and again ty very much
Todlerone
Re: Dynamic css
Posted: Fri Jul 24, 2009 3:25 am
by DaiLaughing
How are the lines of text variable? Where do they come from?
min-height: might help
Re: Dynamic css
Posted: Fri Jul 24, 2009 11:37 am
by andyhoneycutt
Todlerone wrote:TY very very much Andy. I'm not familiar with javascript so I will try to integrate it with my current code.
Cheers and again ty very much
Todlerone
You're welcome, glad I could help!