Hide/show div with css only where it happens "onclick" - can this be done?

Discussion in 'CSS' started by qwikad.com, Feb 4, 2012.

  1. #1
    First, I am not looking for a javascript solution.I found decent CSS codes where it can be done with hover over option, but I want for the text/links to show onclick. You click a link it opens something, you click it again it closes it. Can this be done with CSS alone at all? Any help will be appreciated.
     
    qwikad.com, Feb 4, 2012 IP
  2. chiller4life

    chiller4life Member

    Messages:
    108
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #2
    just create 2 html pages one with showing and one with not showing and link them up with each other
     
    chiller4life, Feb 7, 2012 IP
  3. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,279
    Likes Received:
    1,696
    Best Answers:
    31
    Trophy Points:
    475
    #3
    Not a bad idea. But in my case it won't work as I have hundreds of pages involved (it's a classified site). So... it will be pain in the butt to try to do something like that.
     
    qwikad.com, Feb 7, 2012 IP
  4. chiller4life

    chiller4life Member

    Messages:
    108
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #4
    read the topic below onli one page play around with it mite help m not sure

    http://w3schools.com/cssref/sel_hover.asp


    a:link {color:green;}
    a:visited {color:white;}
    a:hover {color:red;}
    a:active {color:white;}
     
    chiller4life, Feb 8, 2012 IP
  5. chiller4life

    chiller4life Member

    Messages:
    108
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #5
    • a:link - a normal, unvisited link
    • a:visited - a link the user has visited
    • a:hover - a link when the user mouses over it
    • a:active - a link the moment it is clicked

    http://www.w3schools.com/css/css_link.asp

    sorri the first one is wrong link this is the right one.

    mite help m not sure
     
    chiller4life, Feb 8, 2012 IP
  6. simoncrequer

    simoncrequer Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    You could try:

    div {
    visibility: hidden;
    }
    div:active {
    display: visible;
    }

    But I think that would only work when you hold the mouse button down.
     
    simoncrequer, Feb 9, 2012 IP
  7. simoncrequer

    simoncrequer Peon

    Messages:
    26
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    visibility not ​display
     
    simoncrequer, Feb 9, 2012 IP
  8. qwikad.com

    qwikad.com Illustrious Member Affiliate Manager

    Messages:
    7,279
    Likes Received:
    1,696
    Best Answers:
    31
    Trophy Points:
    475
    #8
    I will definitely try this. Sounds like it might work. Thanks for the tip.
     
    qwikad.com, Feb 9, 2012 IP
  9. ZZap

    ZZap Peon

    Messages:
    3
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    You can also use links to set $_get variables. For example
    
     <?php 
    IF($_GET['id']!=5){print ("<a href='?id=5'>Message 5</a>");}IF($_GET[id]==5){ print ("<a href='?id='>Text goes here</a>");}
    ?>
    
    
    Code (markup):
     
    Last edited: Feb 9, 2012
    ZZap, Feb 9, 2012 IP
  10. frei

    frei Greenhorn

    Messages:
    6
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    11
    #10
    I don't think that's the job of CSS. It's job is to style the content. Why don't you use jQuery or something like that?
     
    frei, Feb 12, 2012 IP
  11. spaculus

    spaculus Peon

    Messages:
    187
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #11
    You can't do click event in css You must use Javascript for that. In css you can do Mouse hover, focus and active....
     
    spaculus, Feb 16, 2012 IP
  12. chiller4life

    chiller4life Member

    Messages:
    108
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    26
    #12
    chiller4life, Feb 16, 2012 IP
  13. Andre91

    Andre91 Peon

    Messages:
    197
    Likes Received:
    1
    Best Answers:
    1
    Trophy Points:
    0
    #13
    OP, what you're trying to do could NEVER be achieved with pure CSS. You MUST use JavaScript for a click event. The :active selector in CSS doesn't work the same. You have two options:

    1) Use Javascript. Embed jQuery into your header and there are functions built in to achieve the desired functionality.

    2) Use PHP or any other server side language to pass variables when you click the link, which will tell the next page to show the hidden div. Since it's a text link, you can only pass the variable via the "get" method if you want to go purely PHP (or whatever server side language you use).

    However, I would use a combination of jQuery and PHP if I were you, along with JavaScript's <noscript></noscript> tags. That way if JavaScript is enabled, you can achieve what you want using JavaScript, but if it isn't, your HTML would rely on PHP instead. That's the logic I normally go for.
     
    Andre91, Feb 16, 2012 IP