0

This is for a Rock, Paper, Scissors game that I'm working on. I'm trying to make the sub-text slide in when you hover over the hands, but I can't seem to get it to work. What am I missing?

.choices {
  display: flex;
  flex-direction: column;
}

.hands {
  height: 50%;
  display: flex;
  align-items: flex-end;
  justify-content: space-evenly;
}

.far {
  font-size: 5vh;
  cursor: pointer;
}

.subText {
  height: 50%;
  display: flex;
  justify-content: space-evenly;
}

#rock,
#paper,
#scissors {
  opacity: 0;
  height: 0;
  background-color: rgb(100, 100, 100);
  text-align: center;
  margin-top: 0.5vh;
  margin-left: 2vh;
  font-size: 2vh;
  transition: 0.3s;
}

.fa-hand-rock:hover+#rock {
  opacity: 1;
  height: 40%
}

.fa-hand-paper:hover+#paper {
  opacity: 1;
  height: 40%
}

.fa-hand-scissors:hover+#scissors {
  opacity: 1;
  height: 40%
}
<section class="choices">
  <div class="hands">
    <i class="far fa-hand-rock" onclick="game(1)"></i>
    <i class="far fa-hand-paper" onclick="game(2)"></i>
    <i class="far fa-hand-scissors" onclick="game(3)"></i>
  </div>
  <div class="subText">
    <h6 id="rock">Rock</h6>
    <h6 id="paper">Paper</h6>
    <h6 id="scissors">Scissors</h6>
  </div>
</section>
Sfili_81
  • 1,537
  • 3
  • 16
  • 27
David Skx
  • 141
  • 8
  • 1
    You won’t be able to do it with CSS with your current page structure unfortunately. This needs a JavaScript solution. If you put your elements in the same scope, then CSS can help. – Dan Mullin Aug 28 '20 at 15:11
  • Thank you I went with the JavaScript method. – David Skx Aug 28 '20 at 16:03

1 Answers1

0

.hands{
  padding:40px;
}
.choices {
  display: flex;
  flex-direction: column;
}
.far {
  font-size: 20px;
  cursor: pointer;
  margin:0 50px;
}

.subText {
  display: block;
}

#rock,
#paper,
#scissors {
  opacity: 0;
  background-color: rgb(100, 100, 100);
  font-size: 12px;
  transition: 0.3s;
  display:inline-block;
  text-align:center;
  width:100px;
  margin:10px 15px;
}

.fa-hand-rock:hover~.subText #rock {
  opacity: 1;
}

.fa-hand-paper:hover~.subText #paper {
  opacity: 1;
}

.fa-hand-scissors:hover~.subText #scissors {
  opacity: 1;
}
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
<section class="choices">
  <div class="hands">
    <i class="far fa-hand-rock" onclick="game(1)"></i>
    <i class="far fa-hand-paper" onclick="game(2)"></i>
    <i class="far fa-hand-scissors" onclick="game(3)"></i>
    <div class="subText">
      <h6 id="rock">Rock</h6>
      <h6 id="paper">Paper</h6>
      <h6 id="scissors">Scissors</h6>
    </div>
  </div>
</section>