Archive for the ‘css’ Category

Change the css class of every second row with php

Tuesday, April 28th, 2009

If you need to find odd numbers in an array in php it’s very easy. You just use the “%” command. eg.

if ($num % 2) {
echo “$num is odd”;
} else {
echo “$num is even”;
}

I think what it basically does is divides the number by 2 and if it’s not a whole number it renders it returns it as odd.

Here’s how this code can be very tidy and useful:

The following code can be helpful if you are doing a php foreach repeater to produce a table and you want to use an alternating css class on every second row.

Step 1:
Place a $count outside your foreach loop.

$count=”0″;

Step 2:
Create your rows with the alternating css classes

echo “<tr class =’”;
$count++;
if ($count % 2) {
echo “rowclass1″; }
else {
echo “rowclass2″;
}
echo “‘>”;
echo “<td>Your row Content</td></tr>”;

That’s it, each row will have a different css class and it saves you having to do each row manually!

Table Rows ALternating

Forcing a scroll bar on your browser with css.

Monday, April 27th, 2009

Often when you have some long pages and some short your page may jump slightly horizontally which can be qutie annoying.
This can be caused by the scroll bar sometimes being there and sometimes not, and this will vary depending on the size of the monitor.

One way to get around this is to force a scroll bar on every page. This will make sure the page wont jump no matter the size of the monitor.

The fix for this is very simple. Just add the following to your css file:

body {

overflow-y:scroll;

{