Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why isn't CSS visibility working?

Tags:

visibility

css

I added a "spoiler" class in CSS to use for, well, spoilers. Text is normally invisible but appears when the mouse hovers over it to reveal the spoiler to whoever wants to read it.

.spoiler{
    visibility:hidden;

}
.spoiler:hover {
    visibility:visible;
}

Should be simple, but for some reason this doesn't work. The text remains invisible even when I point the mouse on it. Any idea what could be causing this?

like image 711
Yves Avatar asked Feb 08 '11 03:02

Yves


3 Answers

You cannot hover over a hidden element. One solution is to nest the element inside another container:

CSS:

.spoiler span {     visibility: hidden; }  .spoiler:hover span {     visibility: visible; } 

HTML:

Spoiler: <span class="spoiler"><span>E.T. phones home.</span></span> 

Demo:

http://jsfiddle.net/DBXuv/

Update

On Chrome, the following can be added:

.spoiler {     outline: 1px solid transparent; } 

Updated demo: http://jsfiddle.net/DBXuv/148/

like image 56
Ates Goral Avatar answered Sep 25 '22 16:09

Ates Goral


It works not only for text

.spoiler {     opacity:0; } .spoiler:hover {     opacity:1;     -webkit-transition: opacity .25s ease-in-out .0s;     transition: opacity .25s ease-in-out .0s; } 
like image 30
Jon Ander Avatar answered Sep 22 '22 16:09

Jon Ander


When the text is invisible, it practically does not occupy space, so it's practically imposible to trigger an hover event.

You should try another approach, for example, changing the font color:

.spoiler{
    color:white;

}
.spoiler:hover {
    color:black;
}
like image 30
leonbloy Avatar answered Sep 25 '22 16:09

leonbloy