473,320 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Odd/even list items diferenciation

Hello,

I've been looking for sometime to get a way to diferenciate odd from
even items of a list. The idea would be to diferentialy decorate
alternate rows of a database search result by, for instance, giving
them a diferent background color (white versus light gray, eg). Any
ideas, examples?

Thanks in advance.
Angel

Jul 21 '05 #1
7 6640
Ángel wrote:
Hello,

I've been looking for sometime to get a way to diferenciate odd from
even items of a list. The idea would be to diferentialy decorate
alternate rows of a database search result by, for instance, giving
them a diferent background color (white versus light gray, eg). Any
ideas, examples?

Thanks in advance.
Angel

..odd { background-color: white; }
..even { background-color: #eee; }

not much of a revolution is it.

i would have been nice if the list options would have provided some
solution but i dont think there is any.

gl
martin!
Jul 21 '05 #2
Ángel wrote:
I've been looking for sometime to get a way to diferenciate odd
from even items of a list. The idea would be to diferentialy
decorate alternate rows of a database search result by, for
instance, giving them a diferent background color (white versus
light gray, eg). Any ideas, examples?


Assuming that the table is generated server-side (php, asp), use the
modulo function to determine if the row is odd or even, then insert a
style for the <td>'s.

Here's a slimmed down part from one of my pages:
http://www.countryrode.com/sales/bmwnew.php

CSS:
td.cbar { background: #b0e0e6; }

PHP:
$i=0; $j=1;
while ($i < $num) {
/* Convert to variables */
$strcolor = "";
$cstocknr=mysql_result($d,$i,"cstocknr");
// Which color for this row
if ($j%2 ) { $strcolor = "class='cbar'"; }

echo "<tr>\n";
echo "<td ".$strcolor.">".$cstocknr."</td>\n";
echo "</tr>\n";

/* End of row */
$i++; $j++;
}

--
-bts
-This space intentionally left blank.
Jul 21 '05 #3
Martin! <m.*******@gmail.komkommer> wrote:
Ángel wrote:
I've been looking for sometime to get a way to diferenciate odd from
even items of a list. The idea would be to diferentialy decorate
alternate rows of a database search result by, for instance, giving
them a diferent background color (white versus light gray, eg). Any
ideas, examples?
.odd { background-color: white; }
.even { background-color: #eee; }

not much of a revolution is it.


Not at all :-)
i would have been nice if the list options would have provided some
solution but i dont think there is any.


Yes, the one I was hopping for. Or, at least, for a way which would not
require to tag every item list independetly.

Thanks anyhaw :-)

Cheers,
Angel
Jul 21 '05 #4
Beauregard T. Shagnasty <a.*********@example.invalid> wrote:
Ángel wrote:
I've been looking for sometime to get a way to diferenciate odd
from even items of a list. The idea would be to diferentialy
decorate alternate rows of a database search result by, for
instance, giving them a diferent background color (white versus
light gray, eg). Any ideas, examples?


Assuming that the table is generated server-side (php, asp), use the
modulo function to determine if the row is odd or even, then insert a
style for the <td>'s.


In fact it is a PHP server side generate list. I try your solution
inserting a style for the <li>'s :-)

Thanks a lot.
Angel
Jul 21 '05 #5
"Martin!" <m.*******@gmail.komkommer> wrote:
.odd { background-color: white; }
.even { background-color: #eee; }


Naturally with <tr class="odd"> and <tr class="even"> for alternating
rows. But you can make things a little simpler: generate just <tr
class="even"> for even rows (and <tr> for odd rows) and use

tr { background: white; color: black; }
tr.even { background: #eee; color: block; }

(Write 100 times: "Always set color when setting background, and vice
versa, and set background image too, for safety." Setting background
instead of background-color sets background-image: none.)

--
Yucca, http://www.cs.tut.fi/~jkorpela/
Jul 21 '05 #6
You could do it with JavaScript too, here's an example implementation:

http://www.tobymiller.com/downloads/...row_colors.htm

-tm

Jul 21 '05 #7
Toby Miller <tm*****@tobymiller.com> wrote:
You could do it with JavaScript too, here's an example implementation:

http://www.tobymiller.com/downloads/...row_colors.htm


Thank you, but I do not use JavaScript for giving style. The CSS
aproach works very well.

Cheers,
Ángel
Jul 21 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Simon | last post by:
Hi, I'm hoping you could show me examples of how a functional/declarative language could be used to consicely describe resticted subsets of elements. I'm looking for a 'specification' style...
21
by: M. Clift | last post by:
Hi All, Could someone help me out with this? items = ('a', 'b', 'c', 'd') items + 1 = ( 'b', 'c', 'd', 'a') items + 2 = ( 'c', 'd', 'a', 'b') items + 3 = ( 'd', 'a', 'b', 'c') trans = 1
1
by: NickB | last post by:
Please could someone tell me what is wrong. Ther error is: An unhandled exception of type 'System.NullReferenceException' occurred in microsoft.visualbasic.dll Additional information: Object...
2
by: Yoshitha | last post by:
hi I have 2 drop down lists in my application.1st list ontains itmes like java,jsp,swings,vb.net etc.2nd list contains percentage i.e it conatains the items like 50,60,70,80,90,100. i will...
0
by: Brian Henry | last post by:
Since no one else knew how to do this I sat here all morning experimenting with this and this is what I came up with... Its an example of how to get a list of items back from a virtual mode list...
0
by: Brian Henry | last post by:
Here is another virtual mode example for the .NET 2.0 framework while working with the list view. Since you can not access the items collection of the list view you need to do sorting another...
3
by: Kriston-Vizi Janos | last post by:
Dear Mr. Kern, and Members, Thank you very much for the fast answer, my question became over-simplified. My source code is appended below. It uses two text files (L.txt and GC.txt) as input...
7
by: Jonathan Wood | last post by:
I've been given a spec that seems unwieldy to me. As I'm pretty new to DB design, I would appreciated any input this spec. The site has three types of users: ADMIN, RESELLERS, and CLIENTS. The...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.