another rollover ?

Discussion in 'CSS' started by Navarone, Feb 1, 2008.

  1. #1
    How do I get css to turn my hover state on so it is on all the time? When I rollover my menu my css works fine. When I actually click on my menu and land on that page, I want my menu option to always be in it's hover state. I hope that makes sense. Can you do this in css?
    
    .learn_more
    {
    	background-image: url('../images/menu/learn_more_off.jpg');
    	width: 120px;
    	height: 43px;
    }
    
    .learn_more:hover 
    {
    	background-image: url('../images/menu/learn_more_on.jpg');
    	cursor:pointer;	
    }
    
    Code (markup):

     
    Navarone, Feb 1, 2008 IP
  2. jorgy

    jorgy Peon

    Messages:
    611
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #2
    You'd be better off using AJAX to accomplish this.
     
    jorgy, Feb 1, 2008 IP
  3. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That's an intresting viewpoint, care to elaborate?

    Anyway, i think the following should work.


    
    .learn_more
    {
    	background-image: url('../images/menu/learn_more_on.jpg');
    	cursor:pointer;	
    	width: 120px;
    	height: 43px;
    }
    
    Code (markup):
     
    nicangeli, Feb 1, 2008 IP
  4. jorgy

    jorgy Peon

    Messages:
    611
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #4
    That's not going to work. If he were to use that method the learn more tab would always be open, regardless of whether he was on that page. Unless he was using different stylesheets for each page that is.
     
    jorgy, Feb 1, 2008 IP
  5. jorgy

    jorgy Peon

    Messages:
    611
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Oh, and what I meant when I said it would be easier to use ajax, is that ajax makes it much easier to have dynamic content on your page. A menu that kept drop down tabs open once you're on a certain page requires dynamic coding, and it's pretty hard to do that with just css and html.
     
    jorgy, Feb 1, 2008 IP
  6. nicangeli

    nicangeli Peon

    Messages:
    828
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Who mentioned anything about drop downs?

    Anyway, you are correct, the code i posted will not work. OP, try applying a different class to the menu on the page that you want the :hover state on, and then appy my code to that new class.
     
    nicangeli, Feb 2, 2008 IP
  7. blueparukia

    blueparukia Well-Known Member

    Messages:
    1,564
    Likes Received:
    71
    Best Answers:
    7
    Trophy Points:
    160
    #7
    Does it have any child elements?

    If it is a drop down menu, use:

    .learn_more:active instead of :hover.

    Then for child elements, use:

    
    .learn_more:active li{
    
    }
    
    Code (markup):
    I am assuming your menu is using HTML like this?
    
    <ul>
    <li><a href="#">Dropdown</a>
        <ul>
        <li>List Item 1</li>
        </ul>
    </li>
    </ul>
    
    Code (markup):
     
    blueparukia, Feb 2, 2008 IP
  8. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #8
    That's the sentance most of the responders so far failed to comprehend... at least if I'm reading it right.

    You basically want the 'current' page to be the same as the hover state... so if you are on the home page, the HOME button is lit up - if you are on the links page, the LINKS button is lit up - and so forth, right?

    To do that, you have to add a class to the 'current' link... I usually call this class 'current' - on each page you have to change this on the menu... If you are sharing the same menu code via an SSI, trap it in the SSI to parse the output - if in HTML, then each page needs it's own version of the menu (which is why most people use a SSI/CGI/PAFNA)
     
    deathshadow, Feb 2, 2008 IP
  9. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #9
    WHAT ON EARTH

    why would you need XHR for?

    <?php
    // about.php
    $page = 'about';

    <ul id="nav">
    <li <?php echo ($page == 'about' ? ' class="current" ' : ''); ?>><a href="#">foo</a></li>
    </ul>
    ?>

    CSS:
    ul#nav li a:hover, ul#nav li.current a { /* hover state declarations */ }
    ul#nav li a { /* normal state */ }

    and something similar for each nav item.. php seems to be the most favored language here so that's why i used it in the ex.

    note: you'd get an error if error reporting is set to the highest unless you also checked if the $page variable was set in the first place.
     
    soulscratch, Feb 2, 2008 IP
  10. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #10
    Um Soulscratch - you have your CSS backwards - hover and .current should be BEFORE the parent declaration - Also I'd not be opening and closing PHP every line like a script kiddie (just a gentle ribbing buddy ;)
     
    deathshadow, Feb 3, 2008 IP
  11. soulscratch

    soulscratch Well-Known Member

    Messages:
    964
    Likes Received:
    45
    Best Answers:
    0
    Trophy Points:
    155
    #11
    D'oh, wasn't thinking on the css part. How would you spit the nav out? Do everything inside of (one pair of) php delimiters?
     
    soulscratch, Feb 3, 2008 IP
  12. deathshadow

    deathshadow Acclaimed Member

    Messages:
    9,732
    Likes Received:
    1,999
    Best Answers:
    253
    Trophy Points:
    515
    #12
    I'm a firm believer that if you are going to use php on a page, you should open it once at the very start of the page, and close it once at the very end.

    As such, that would end up inside an echo, reading:

    echo '
    	<ul id="nav">
    		<li',(
    			$page=='about' ?
    			' class="current"' :
    			''
    		),'><a href="#">foo</a></li>
    	</ul>
    ';
    Code (markup):
    Mind you, that's following my own style guide, which tends to use a few more tabs and carriage returns than what other people use... AND tends to output HTML with proper indenting.
     
    deathshadow, Feb 3, 2008 IP