Yash Gugaliya
Yash Gugaliya

Reputation: 31

When user hovers on an element change properties of another element

.social-buttons ul li .fab:hover{
  font-size: 30px;
}

.social-buttons{
    position: absolute;
    top: 100px;
    left: 20px;
}
.social-buttons ul{
    list-style: none;
}
.social-buttons ul li{
    position: relative;
    height: 50px;
    width: 50px;
    background-color: white;
    border-radius: 10px;
    margin: 10px 0px;
    box-shadow: 0 0 10px rgba(0,0,0,0.3);
}
.social-buttons ul li .fab{
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%,-50%);
    font-size: 25px;
}
.social-buttons ul li .fab:hover{
  font-size: 30px;
}
<script src="https://kit.fontawesome.com/fc692f1356.js" crossorigin="anonymous"></script>
<div class="social-buttons">
  <ul>
    <a href="#">
      <li>
        <i class="fab fa-instagram"></i>
      </li>
    </a>
    <a href="#">
      <li>
        <i class="fab fa-pinterest"></i>
      </li>
    </a>
    <a href="#">
      <li>
        <i class="fab fa-facebook-f"></i>
      </li>
    </a>
    <a href="#">
      <li>
        <i class="fab fa-youtube"></i>
      </li>
    </a>
  </ul>

I wrote the above code. It only increases the font size when hovering on only icons. In the above fiddle . I want to change the font size(icon size) of .fab(icons) when the user hovers on .social-buttons ul li(the box covering the social media icons)

Upvotes: 0

Views: 40

Answers (1)

connexo
connexo

Reputation: 56754

Replace .social-buttons ul li .fab:hover{ with .social-buttons ul li:hover .fab{.

Please note that your HTML is currently invalid. You have useless a tags wrapping your list items. Remove those, they're not allowed at that point. ul can only have li children. If you want the link-like mouse cursor, just add cursor: pointer; on the li.

.social-buttons {
  position: absolute;
  top: 100px;
  left: 20px;
}

.social-buttons ul {
  list-style: none;
}

.social-buttons ul li {
  position: relative;
  height: 50px;
  width: 50px;
  background-color: white;
  border-radius: 10px;
  margin: 10px 0px;
  box-shadow: 0 0 10px rgba(0, 0, 0, 0.3);
  cursor: pointer;
}

.social-buttons ul li .fab {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 25px;
}

.social-buttons ul li:hover .fab {
  font-size: 30px;
}
<script src="https://kit.fontawesome.com/fc692f1356.js" crossorigin="anonymous"></script>
<div class="social-buttons">
  <ul>
    <li>
      <i class="fab fa-instagram"></i>
    </li>
    <li>
      <i class="fab fa-pinterest"></i>
    </li>

    <li>
      <i class="fab fa-facebook-f"></i>
    </li>
    <li>
      <i class="fab fa-youtube"></i>
    </li>
  </ul>
</div>

Upvotes: 1

Related Questions