Home > Software design >  Tooltip not showing at all using CSS
Tooltip not showing at all using CSS

Time:11-03

I am trying to display a tooltip at my code page, I tried adding z-index at the css, but it did not work, i tried change the display to inline-block but still the same.

Here is my code:

.tooltip {
    position: relative;
    display: inline-block;
    background-color: transparent;
    border-width: 0px;
    margin: 0px;
    padding: 0px;
    float: none;
    z-index: 9999999
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 355px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    opacity: 0;
    transition: opacity 1s;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<div class="tooltip">
     <i class="fa fa-info-circle"></i>
     <span class="tooltiptext">Hello nice to meet u!</span>
</div>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

The following images are what I can see from enter image description here

CodePudding user response:

You just need to work on the positioning, look at my example, i just added position:absolute and top and left property and it looks good to me, you can easily work with the dev-tools element inspector on this when you "force state hover"

.tooltip {
    position: absolute;
    display: inline-block;
    background-color: transparent;
    border-width: 0px;
    margin: 0px;
    top:40px;
    left:40px;
    padding: 0px;
    float: none;
    z-index: 9999999
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 355px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px;
    position: absolute;
    z-index: 1;
    bottom: 125%;
    left: 50%;
    opacity: 0;
    transition: opacity 1s;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<div class="tooltip">
     <i class="fa fa-info-circle"></i>
     <span class="tooltiptext">Hello nice to meet u!</span>
</div>
<iframe name="sif2" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

CodePudding user response:

Change .tooltip .tooltiptext { bottom: 125%; } .

Snippet:

.tooltip {
    position: relative;
    display: inline-block;
    background-color: transparent;
    border-width: 0px;
    margin: 0px;
    padding: 0px;
    float: none;
    z-index: 9999999
}

.tooltip .tooltiptext {
    visibility: hidden;
    width: 355px;
    background-color: #555;
    color: #fff;
    text-align: center;
    border-radius: 6px;
    padding: 5px;
    position: absolute;
    z-index: 1;
    /*bottom: 125%;*/
    left: 50%;
    opacity: 0;
    transition: opacity 1s;
}

.tooltip:hover .tooltiptext {
    visibility: visible;
    opacity: 1;
}
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css" integrity="sha512-YWzhKL2whUzgiheMoBFwW8CKV4qpHQAEuvilg9FAn5VJUDwKZZxkJNuGM4XkWuk94WCrrwslk8yWNGmY1EduTA==" crossorigin="anonymous" referrerpolicy="no-referrer" />

<div class="tooltip">
     <i class="fa fa-info-circle"></i>
     <span class="tooltiptext">Hello nice to meet u!</span>
</div>
<iframe name="sif3" sandbox="allow-forms allow-modals allow-scripts" frameborder="0"></iframe>

  • Related