Not sure if I’m tired or what. Trying to make setup where there are multiple elements with span class which when hovered upon will make appear some text in a Div. Any tips on how to make this work and maybe even make it more compact. Thanks.
.hide {
display: none;
min-height: 200px;
}
.hide2 {
display: none;
border: solid #ff8900 2px;
border-radius: 20px;
padding: 20px;
min-height: 200px;
}
.myLINK:hover + .hide {
display: block;
color: gray;
}
.myLINK2:hover + .hide2 {
display: block;
color: gray;
}
<h2>Display an Element on Hover</h2>
<span class="myLINK">Hover over me 1.</span> | <span class="myLINK">Hover over me 2.</span>
<div class="hide">I am shown when someone hovers over the div above.</div>
<div class="hide2">I am shown when someone hovers over the div above2.</div>
Need to show text in a div when hovering on top of span/class element.
3
Answers
References :
https://www.w3schools.com/cssref/sel_gen_sibling.php
https://www.w3schools.com/cssref/sel_element_pluss.php
You need to use
~
selector.You have used
+
inCSS
, which is used for sibling elements.The correct approach is following, I also have updated class names for ease of understanding:
You don’t need to repeat the code for each hidden div, just wrap components under single div and apply the CSS