Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CSS show div on hover

Tags:

html

hover

This is my CSS

.header_under{
    display: none;
    width: 300px;
    height: 150px;
    float: left;
    background: red
}
.show:hover ~ .header_under{
    display: block;
}

So what I want is the "header_under" to appear on the website on hover. But it seems not to work

HTML:

<li class="show"><a href='#'><span>Games4u</span></a></li>

And

<div class="bildspel">
    <div id="header_under"></div>
</div>
like image 916
i5dogdgg Avatar asked Dec 05 '25 21:12

i5dogdgg


1 Answers

Your HTML needs to be structured to match the CSS and it will work.

The tilde (~) operator requires a sibling connection with the target:

#header_under{
    display: none;
    width: 300px;
    height: 150px;
    background: red
}
.show:hover ~ #header_under{
    display: block;
}
<ul>
    <li class="show">
        <a href='#'><span>Games4u</span></a>
    </li>
    <div id="header_under">dasasdadssad</div>
</ul>
like image 154
Joel Peltonen Avatar answered Dec 08 '25 16:12

Joel Peltonen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!