SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2006
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    css change color background after click

    I have a sidebar with links. If one of the links is clicked and they stay in that section, then I want the background color to stay yellow. If they click on another link, then new link background becomes yellow, but old link goes back to colorless state.

    Sidebar nav is different for each section in webapp. Links in the sidebar differs and links maybe created dynamically from different section of webapps?

    Is this only possible if you know the links before hand, so you can define in id CSS ?

    any idea?

    I need something like gmail, chat is highlighted with blue background:
    Attached Images Attached Images
    Last edited by johnCash; Oct 8, 2007 at 05:38. Reason: Add gmail pic

  2. #2
    SitePoint Wizard bronze trophy DaveWoods's Avatar
    Join Date
    Dec 2004
    Location
    Derbyshire - UK
    Posts
    2,651
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Gmail uses JavaScript/AJAX to deliver the behaviour so you'll need to go down that route.

    CSS is for presentation only so you can't do that without reloading the page.

  3. #3
    The CSS Clinic is open silver trophybronze trophy
    Paul O'B's Avatar
    Join Date
    Jan 2003
    Location
    Hampshire UK
    Posts
    40,549
    Mentioned
    183 Post(s)
    Tagged
    6 Thread(s)
    If one of the links is clicked and they stay in that section,
    Where are they going when they click the link then? If you are using javascript to display some content then you may as well swap the elements class via javascript at the same time to show the background color you want.

    You can fake something similar with css but its not reliable cross browser and the links lose their status when anything else is clicked.

    http://www.pmob.co.uk/temp/hideandshow3-css.htm#

    However I wouldn't advise using this method as its for example only.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •