Skip to main content
Welcome guest. | Register | Login | Post

Need Some CSS

6 replies [Last post]
supermike's picture
Joined: 2006-02-17

I need some CSS where I have a grid table with rows that alternate in color. I can do this in Javascript or PHP, of course, but how do I do it purely with CSS, if that's even possible? Probably not, right?

a thing's picture
Joined: 2005-12-20

No, you need to at least set the id attribute of the <td>s.

libervisco's picture
Joined: 2006-05-04
"a thing" wrote:

No, you need to at least set the id attribute of the <td>s.

Isn't that obvious? Eye

CSS is meaningless without html I'd say.

tbuitenh's picture
Joined: 2005-12-21

I'd use class instead of id, cause you don't want separate ids and css bits for every row.
Maybe you can think of a clever trick with :first-line , but I can't :-P

Joined: 2006-03-28

I don't think there's a pure CSS-solution, just some PHP-HTML-CSS-combo like this:

<style type="text/css">
for ($x=0;$x<10;$x++)
 echo '<tr class="line'.($x%2).'"><td>Test</td><td>'.$x.'</td></tr>';
free-zombie's picture
Joined: 2006-03-08

I'd make it a php function...

Joined: 2006-03-28
"free-zombie" wrote:

I'd make it a php function...

Well, I think that depends.
I think usually you won't do it the way I've shown in the example.
Let's say you get your data from a database and use a WHILE-loop to output everything.
You just add a counter and use the modulo-divison to decide which CSS-class should be used for the line.
A function for that is, in my oppinion, absolutely not necessary.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.