Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 6 of 6
  1. #1
    Member
    Join Date
    Oct 2002
    Location
    USA
    Posts
    94
    Member #
    237

    Current Rating

    Visual Appeal:
    0.0 out of 5

    Accessibility:
    0.0 out of 5

    Website Speed:
    0.0 out of 5

    Compatibility:
    0.0 out of 5

    Overall Rating:
    0.0 out of 5

    Rate This Site


    Advertisement (login to hide this!)


    You must be logged in to view this site

    Tables: Alternating TD background colors

    Hello. I am attempting to create a table in which the background color of its data cells alternates between 2 colors; specifically the effect created here. Currently I simply use the <TD bgcolor=""> Tag attribute, but I want to make it automatically alternate the colors upon creation of new Data cells so I can add links anywhere within my alphabetical list, and not have to change the attributes every time I modify the list; that can become time consuming. Additionaly, I have other tables within my site that I do not want altered at all. How might I go about this? Can it be done with CSS, even though I only want to affect some tables? Thanks in advance for any information..

  2.  

  3. #2
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    I don't believe there is a way to do this with pure CSS/HTML (remember they're not programming or even scripting languages). Your best bet would be to do something like
    PHP Code:
    $colorswitch 1;
    $firstaltcolor "#EEEEEE";
    $secondaltcolor "#FFFFFF";

    function 
    createtdbgcolor()
    {
        
    $colorswitch = !$colorswitch;
        return (
    $colorswitch $firstaltcolor $secondaltcolor);

    Then, every time you want to make a td (this assumes one td per tr):
    Code:
    <td bgcolor="<? echo createtdbgcolor(); ?>">...</td>
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  4. #3
    Member
    Join Date
    Oct 2002
    Location
    USA
    Posts
    94
    Member #
    237
    Thanks!

    By any chance, would that snippet work even if the page extension was .html? Thanks.

  5. #4
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    Nope, it has to be .php.
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!

  6. #5
    Senior Member energizze's Avatar
    Join Date
    Oct 2002
    Posts
    260
    Member #
    238
    you could do the same with javascript.

    which would be within a html page.

  7. #6
    Senior Member filburt1's Avatar
    Join Date
    Jul 2002
    Location
    Maryland, US
    Posts
    11,774
    Member #
    3
    Liked
    21 times
    ...but remember not all browsers work the same or even support Javascript

    Each to his own
    filburt1, Web Design Forums.net founder
    Site of the Month contest: submit your site or vote for the winner!


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 01:18 PM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com