I know, someone could say, this is a duplicate, but I say something to the answers on two other similar question and they aren't helping me.
Before I explain my problem, I show you this code and what is it for:
<div class="col-3 Hoehe2">
<div class="sibling"></div>
<div class="Hoehe2Oben">
<a class="NormalAussehen" href="Löschen.php?Stadt=<?php echo $StadtIDs[$i] ?>">
<div class="Hoehe2Kaestchen col-3">
<div class="Hoehe2Kreuz">
X
</div>
</div>
</a>
</div>
<div class="Hoehe2Text">
<?
echo $Example;
?>
</div>
</div>
The col-3, Classes set the width. That is the code:
.col-1 {width: 8.33%;}
.col-2 {width: 16.66%;}
.col-3 {width: 25%;}
.col-4 {width: 33.33%;}
.col-5 {width: 41.66%;}
.col-6 {width: 50%;}
.col-7 {width: 58.33%;}
.col-8 {width: 66.66%;}
.col-9 {width: 75%;}
.col-10 {width: 83.33%;}
.col-11 {width: 91.66%;}
.col-12 {width: 100%;}
The whole thing("Hoehe2") is in the proportion 2:1 width:height. I have used this (https://www.w3schools.com/howto/howto_css_aspect_ratio.asp) tutorial. This is the Stylesheet of Hoehe2:
.Hoehe2 {
padding-top: 66.66%;
position: relative;
border: 1px solid #00FF00;
background-color: #1F9F1F;
}
.Hoehe2Oben {
position: absolute;
top: 0;
left: 0;
bottom: 100%;
right: 0;
}
Inside this big div which has the proportion 2:1, I wanted to make a small div, with the same proportion. That was "Hoehe2Kaestchen". Inside Hoehe2Kreuz, there is an X (to delete). So, this code is:
.Hoehe2Kaestchen {
margin-left: 75%;
background-color: #F873F1;
padding-top: 16.66%;
position: relative;
border: 1px solid #00FF00;
}
.Hoehe2Kreuz {
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
text-align: center;
font-size: 4vw;
}
Inside Hoehe2Text, there is the text and the javascript code is
.Hoehe2Text {
position: absolute;
top: 40%;
left: 0;
bottom: 35%;
right: 0;
text-align: center;
border: 1px solid #00FF00;
}
Now, I show you my problem: I want to change the background-color of the Link (respectively the div "Hoehe2Kaestchen") when the mouse is over it. That works with
.Hoehe2Kaestchen:hover {
background-color: #282828;
}
But, if the mouse is over the rest of <div class="Hoehe">
, the background-color of Hoehe should change.
If I made
.Hoehe2:hover {
background-color: #AAA016;/*Test color*/
}
The background color of Hoehe2 would change, if the mouse were over Hoehe2Kaestchen, too!
To prevent that, I wanted to something like this
.Hoehe2Kaestchen:hover ~.Hoehe2 {
background-color: #1F9F1F;
}
But, as Hoehe2 is the parent of Hoehe2Kaestchen, that doesn't work.
I wanted to do it just like in this answer: How to style the parent element when hovering a child element?, and I made
.Hoehe2Kaestchen:hover ~.sibling {
background-color: #1F9F1F;
}
But that isn't working either.
Although this is like my question and the answer worked in the browser ("Run Code Snippet"), it isn't working in my website. What am I doing wrong?
I hope somebody can find my mistake.