Posts tagged with “php”

15 Feb

Alternating background colors

I just wrote some pretty quick code for the age-old problem of alternating colors in a table. I don’t know how this could get any simpler. Sweet!

<? foreach($posts as $post){?>
	<div class="<?=($c++%2==1)?'odd':NULL?>&#8220;&gt;
		<?=$post?>
	</div><br />
<? }?><br />
<style>
	.odd{background-color:red;}<br />
</style>

View Comments · Tags: ,

Forcing a floated line-wrap in PHP

For every 4 floated elements, wrap to the next line:

<?=($b++%4==0)?'<br class="clr" />&#8216;:NULL?&gt;

View Comments · Tags: ,
← Previous Page 2 of 2