toolman Posted August 1, 2012 Share Posted August 1, 2012 Hi, I have some divs that are created automatically, but I am giving the divs a margin-right, which means the last div is breaking onto a new line. Is there a way I can give the last div it's own class? Link to comment https://forums.phpfreaks.com/topic/266545-give-last-div-a-dissferent-class/ Share on other sites More sharing options...
Psycho Posted August 1, 2012 Share Posted August 1, 2012 Yes. Were you wanting more help? Posting some code might help us to do that. Link to comment https://forums.phpfreaks.com/topic/266545-give-last-div-a-dissferent-class/#findComment-1365976 Share on other sites More sharing options...
Psycho Posted August 1, 2012 Share Posted August 1, 2012 Here is a very rudimentary example //Create function to output one DIV of content for a record function displayContent($value, $class) { echo "<div class='{$class}'>{$value}</div>\n"; } //Loop through records to be displayed foreach($arrayOfData as $recordID => $value) { if(isset($prevValue)) { //Create output for previous value/record //Using selected class/style displayContent($prevValue, 'alignRight'); } $prevValue = $value; } //Create output for very last record using a different class displayContent($lastValue, 'alignLeft'); Link to comment https://forums.phpfreaks.com/topic/266545-give-last-div-a-dissferent-class/#findComment-1365979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.