2

Need little CSS help! I want to unhide a elements when another element is hovered.

For example:

<div class="Welcome"><a>Welcome to our site<a><div>
<div class="Message">Thanks for touching me!<div>

CSS

.Message {
    display: hidden
}

.Welcome a: hover {
/*I want to make .Message visible now. Any ideas?*/
}
Kijewski
  • 25,517
  • 12
  • 101
  • 143
Lavanya Arora
  • 75
  • 1
  • 2
  • 7

3 Answers3

6

This is really the best you can get, when you hover over .Welcome .Message is displayed. This uses the adjacent sibling + selector.

.Message {
    display: none;
}

.Welcome:hover + .Message {
    display:block;
}

http://jsfiddle.net/mowglisanu/ZPVSU/

Musa
  • 96,336
  • 17
  • 118
  • 137
  • how is this as far as cross browser support? – Jared Jul 29 '12 at 02:33
  • According to [mdn](https://developer.mozilla.org/en/CSS/Adjacent_sibling_selectors) chrome, ff, opera, safari, IE7+ – Musa Jul 29 '12 at 02:38
  • Thanks, I found this for an additional ref... http://reference.sitepoint.com/css/adjacentsiblingselector although the browsers listed seem rather dated. – Jared Jul 29 '12 at 02:39
  • Hey, thisn't working. To get a better idea, i'm trying to do it with my site's featured area. Link: http://www.thetechnodaily.com .recentpost-1 img:hover + .content-heading { display:block; } .content-heading { display: none; } – Lavanya Arora Jul 29 '12 at 02:47
  • @LavanyaArora use this `.recentpost-1 a:hover + .content-heading { display:block; } .content-heading { display: none; }` instead since `.content-heading` adjacent sibling is the `a`. – Musa Jul 29 '12 at 02:59
  • @LavanyaArora try refreshing your browser, cause I can see it working – Musa Jul 29 '12 at 03:17
  • Guys, do you know how to slow down this animation while opacity is changing? – Lavanya Arora Jul 29 '12 at 03:58
  • @LavanyaArora what animation? Also you might want ask that in new question. Also if an answer solves your problem you should accept it as the answer by clicking on the tick next to it – Musa Jul 29 '12 at 04:18
1

This is really easy with a bit of jQuery.

CSS

​div.Message{
    display:none;
}​

HTML

<div class="Welcome">Welcome to our site<div>
<div class="Message">Thanks for touching me!<div>

jQuery

$('.Welcome').hover(
    function () {
    $('.Message').show();
  }, 
    function () {
    $('.Message').hide();
  }
);

Example: http://jsfiddle.net/gxn34/

EDIT

To answer your question below

You would need to add the following to your page, usually in the <head> section

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>

And

 <script>
     $(document).ready(function(){
        $('.Welcome').hover(
            function () {
        $('.Message').show();
          }, 
            function () {
        $('.Message').hide();
          }
        );
     });
 </script>
Jason Gennaro
  • 34,535
  • 8
  • 65
  • 86
0
.Welcome a: hover {
  display: block;
}
Zombo
  • 1
  • 62
  • 391
  • 407