Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Display hidden css class on hover

Tags:

css

I have few form fields, each input and label is wrapped inside a div in following way:

<div class="field">
    <label for="name">Name:</label>
    <input type="text" class="input" name="name" />
    <p class="hint">Enter your name</p>
</div>

the hint class is initially hidden like display:none.

How can I display the hidden hint class on hover anywhere in class field. Thanks.

like image 714
Jay Avatar asked Feb 27 '11 16:02

Jay


2 Answers

In CSS you can do it the following way:

.hint { display: none; }
.field:hover .hint { display: block; }

Edit: As Karl said, this will not work in Internet Explorer 6. You can, however, resort to JavaScript (in this example using jQuery) to do that:

jQuery(".field").hover(
   function() {
      jQuery(this).find(".hint").css("display","block");
   },
   function() {
      jQuery(this).find(".hint").css("display","none");
   }
);
like image 117
Nils Werner Avatar answered Oct 24 '22 15:10

Nils Werner


This option will work in IE 4 and later.

<div class="field" onmouseover="document.getElementById('hint').style.display='none';"  onmouseout="document.getElementById('hint').style.display='block';">
    <label for="name">Name:</label>
    <input type="text" class="input" name="name" />
    <p id="hint">Enter your name</p>
</div>

And for your other forms just change the id hint2, hint3, etc.

<div class="field" onmouseover="document.getElementById('hint2').style.display='none';"  onmouseout="document.getElementById('hint2').style.display='block';">
    <label for="name">Name:</label>
    <input type="text" class="input" name="name" />
    <p id="hint2">Enter your name</p>
</div>
like image 30
Web_Designer Avatar answered Oct 24 '22 16:10

Web_Designer