I want to get my .dynamic-tooltip
to overlay on my .static-tooltip
. And my static tooltip has to be hidden.
But I am unable to do so with z-index
. Please tell me where am I going wrong.
Please have a look at my code. https://jsfiddle.net/x883m3hg/
<div class = "static-tooltip">
<div class = "tooltip-container">
<div class = "item-key">
Static tooltip Key
</div>
<div class = "item-value">
Static tooltip Value
</div>
</div>
</div>
<div class = "dynamic-tooltip">
<div class = "tooltip-container">
<div class = "item-key">
Dynamic tooltip Key
</div>
<div class = "item-value">
Dynamic tooltip value
</div>
</div>
</div>
.static-tooltip{
position:relative;
z-index:1;
width:100%;
height: 30px;
}
.dynamic-tooltip{
position:absolute;
z-index:2;
top:3px;
width: 100%;
height:30px
}
Thanks in advance.
The body
element has a default margin of 8px. Start by removing that:
body { margin: 0; }
Then reset the top
offset on the dynamic-tooltip
to 0
.
.dynamic-tooltip { top: 0; }
Here's your revised code:
body {
margin: 0; /* new */
}
.static-tooltip {
position: relative;
z-index: 1;
width: 100%;
height: 30px;
background-color: aqua;
}
.dynamic-tooltip {
position: absolute;
z-index: 2;
top: 0px; /* adjusted */
width: 100%;
height: 30px;
background-color: red;
}
<div class="static-tooltip">
<div class="tooltip-container">
<div class="item-key">
Static tooltip Key
</div>
<div class="item-value">
Static tooltip Value
</div>
</div>
</div>
<div class="dynamic-tooltip">
<div class="tooltip-container">
<div class="item-key">
Dynamic tooltip Key
</div>
<div class="item-value">
Dynamic tooltip value
</div>
</div>
</div>
Revised Fiddle
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With