Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What's the exact bug with my CSS hovering code in side nav bar?

**In my social media icons project, I tried hiding my text using opacity 0. When a user will mouse hover on my tag or icons the text will be shown. but my hover transition doesn’t work. Please at first try using opacity 1 in my CSS in .icon.Please solve my hovering problem. I can’t understand what’s the bug

enter image description here

enter image description here

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

:root {
  --darkblu: #2c3e50;
  --linkclr: #fff;
  --lightblue: lightblue;
  --violet: violet;
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

.side_nav {
  background-color: var(--darkblu);
  height: 100vh;
  width: 50px;
  position: fixed;
  display: flex;
  flex-flow: column nowrap;
  justify-content: flex-start;
  align-items: center;
  /* overflow: hidden; */
}

.icon_holder {
  display: flex;
  justify-content: center;
  align-items: center;
  position: relative;
}

.icon {
  width: 100%;
  height: 100%;
  /* background-color: var(--lightblue); */
}

.side_nav .icon_holder .icon a {
  text-decoration: none;
  color: var(--linkclr);
  font-size: 80%;
  /* width: 100%;
        height: 100%; */
  display: inline-block;
  margin: 20px 0px;
  padding: 10px;
}

.icon_holder span {
  position: absolute;
  left: 100%;
  width: 100px;
  background-color: var(--violet);
  margin: 0px 24px;
  padding: 5px;
  text-align: center;
  border-radius: 4px;
  opacity: 0;
}

.icon_holder span::before {
  content: '';
  position: absolute;
  height: 10px;
  width: 10px;
  transform: rotate(45deg);
  background-color: var(--violet);
  top: 35%;
  left: -5%;
}

.icon_holder:nth-child(1):hover .icon_holder span {
  opacity: 1;
}
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <link rel="stylesheet" href="style.css">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.15.4/css/all.css" integrity="sha384-DyZ88mC6Up2uqS4h/KRgHuoeGwBcD4Ng9SiP4dIRy0EXTlnuz47vAwmeGwVChigm" crossorigin="anonymous">
</head>

<body>
  <div class="side_nav">
    <div class="icon_holder">
      <div class="icon"><a href="#"><i class="fas fa-home"></i></a></div>
      <span>Home</span>
    </div>
    <div class="icon_holder">
      <div class="icon"><a href="#"><i class="fas fa-blog"></i></a></div>
      <span>Blog</span>
    </div>
    <div class="icon_holder">
      <div class="icon"><a href="#"><i class="fas fa-question"></i></a></div>
      <span>About Us</span>
    </div>
    <div class="icon_holder">
      <div class="icon"><a href="#"><i class="fab fa-whatsapp"></i></a></div>
      <span>Whatsapp</span>
    </div>
    <div class="icon_holder">
      <div class="icon"><a href="#"><i class="fas fa-user"></i></a></div>
      <span>User Access</span>
    </div>
  </div>
</body>

</html>

>Solution :

Use this:

.icon_holder span {
    position: absolute;
    left: 100%;
    width: 100px;
    background-color: var(--violet);
    margin: 0px 24px;
    padding: 5px;
    text-align: center;
    border-radius: 4px;
    opacity: 0;
    transition: 500ms all;//add transition
}

.icon_holder:hover span{
    opacity: 1;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading