Home > Web Front-end > CSS Tutorial > Why is My Spoiler Text Not Showing on Hover?

Why is My Spoiler Text Not Showing on Hover?

Mary-Kate Olsen
Release: 2024-11-11 18:12:03
Original
722 people have browsed it

Why is My Spoiler Text Not Showing on Hover?

Troubleshooting CSS Visibility Issues for Spoiler Elements

When using the visibility property in CSS to create spoiler elements, some users may encounter difficulties with the text remaining invisible even when hovering over it. This issue can stem from the fact that hovering requires a visible element to interact with.

To resolve this issue, one effective solution is to nest the spoiler element within another container. This allows the container to receive the hover event, even when the spoiler element is initially hidden. The following updated code snippet demonstrates this technique:

CSS:

.spoiler span {
    visibility: hidden;
}

.spoiler:hover span {
    visibility: visible;
}
Copy after login

HTML:

Spoiler: <span>
Copy after login

This approach ensures that the container element becomes visible when hovered, triggering the visibility of the inner spoiler element.

Demo:
http://jsfiddle.net/DBXuv/

Note: For Chrome browsers specifically, the following addition can enhance the functionality:

.spoiler {
    outline: 1px solid transparent;
}
Copy after login

This addition provides a visual cue to indicate the spoiler's presence, even when the initial text is hidden.

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

The above is the detailed content of Why is My Spoiler Text Not Showing on Hover?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template