Hej nie mogę sobie poradzić z kodem poniżej a mianowicie dlaczego działa mi :hover
tylko dla .red
? Wyświetla tekst a dla reszty
<body>
<div class="red circle"></div>
<div class="green circle"></div>
<div class="blue circle"></div>
<div class="orange circle"></div>
<div class="bg">
<p class="red">Czerwony</p>
<p class="green">Zielony</p>
<p class="blue">Niebieski</p>
<p class="orange">Pomarańczowy</p>
</div>
</body>
* {
margin: 0;
padding: 0;
}
.circle {
position: absolute;
width: 50px;
height: 50px;
border-radius: 50%;
border: 2px white solid;
z-index: 1;
}
div:nth-child(1) {
top: 20px;
left: 20px;
background-color: red;
}
div:nth-child(2) {
top: 20px;
right: 20px;
background-color: green;
}
div:nth-child(3) {
bottom: 20px;
left: 20px;
background-color: blue;
}
div:nth-child(4) {
bottom: 20px;
right: 20px;
background-color: orange;
}
.bg {
width: 100%;
height: 100vh;
background-color: grey;
transition: 3s;
}
div:nth-child(1):hover~div.bg {
background-color: red;
}
div:nth-child(2):hover~div.bg {
background-color: green;
}
div:nth-child(3):hover~div.bg {
background-color: blue;
}
div:nth-child(4):hover~div.bg {
background-color: orange;
}
p {
text-align: center;
line-height: 100vh;
font-size: 100px;
color: white;
opacity: 0;
transition: 3s;
}
div:nth-child(1):hover~div.bg p.red {
opacity: 1;
}
div:nth-child(2):hover~div.bg p.green {
opacity: 1;
}
div:nth-child(3):hover~div.bg p.blue {
opacity: 1;
}
div:nth-child(4):hover~div.bg p.orange {
opacity: 1;
}