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
Dynamic css
Moderator: General Moderators
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: Dynamic css
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:
Hope this helps!
-Andy
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>";-Andy
-
Todlerone
- Forum Commoner
- Posts: 96
- Joined: Sun Oct 28, 2007 10:20 pm
- Location: Hamilton, Ontario, Canada
Re: Dynamic css
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
Cheers and again ty very much
Todlerone
-
DaiLaughing
- Forum Commoner
- Posts: 76
- Joined: Thu Jul 16, 2009 8:03 am
Re: Dynamic css
How are the lines of text variable? Where do they come from?
min-height: might help
min-height: might help
- andyhoneycutt
- Forum Contributor
- Posts: 468
- Joined: Wed Aug 27, 2008 10:02 am
- Location: Idaho Falls
Re: Dynamic css
You're welcome, glad I could help!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