Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS - On Hover, Show 'Niece'

Here's the code I have:

<div class="hoverDiv">Hover</div>
<div>
    <div class="hoverDivShow"></div>
</div>



.hoverDivShow {
    display: none;
}
.hoverDiv:hover ~ .hoverDivShow {
    display: block;
}

What I've been trying to do, is make hoverDivShow appear when hoverDiv is hovered over.

The HTML won't be able to change.

I've looked elsewhere, and have been unable to find any solutions. Not really sure what I'm doing right/wrong. Help would be nice.

Thanks!

like image 491
polyps Avatar asked Nov 13 '15 19:11

polyps


People also ask

How do you make something appear when you hover over it CSS?

To display div element using CSS on hover a tag: First, set the div element invisible i.e display:none;. By using the adjacent sibling selector and hover on a tag to display the div element.

How do I target a sibling in CSS?

The adjacent sibling combinator ( + ) separates two selectors and matches the second element only if it immediately follows the first element, and both are children of the same parent element .

How do I show text on hovering?

Set visibility: hidden and opacity: 0 for not displaying image first time. Using transition property for adding animation. When hovering on parent <div> then change the child element visibility: visible and opacity: 0.7; . You can change the position of text container using the top bottom left right CSS properties.

How do I show hover image in CSS?

Answer: Use the CSS background-image property You can simply use the CSS background-image property in combination with the :hover pseudo-class to replace or change the image on mouseover.


1 Answers

You need to use .hoverDiv:hover ~ div .hoverDivShow as the "niece" selector. The idea is to select a <div> that is the sibling of .hoverDiv, then select a child of that sibling that has the class hoverDivShow.

Here's a working demo:

.hoverDivShow {
    display: none;
}
.hoverDiv:hover ~ div .hoverDivShow {
    display: block;
}
<div class="hoverDiv">Hover</div>
<div>
    <div class="hoverDivShow">I'm hidden until you hover!</div>
</div>
like image 71
elixenide Avatar answered Oct 02 '22 01:10

elixenide