Why does the tooltip content align with the left edge of its parent in the following code snippet?
If i give the display of .tooltip-trigger
class as inline-block
the content aligns with the left edge, but if i do not give the .tooltip-trigger
class inline block the content aligns with the left edge of the body.
I am not able to understand this behaviour of position absolute. Can someone please explain why inline-block affects the positioning of the element with position absolute.
tooltip-trigger
- inline-block
Content aligned with left edge of parent
tooltip-trigger
- without inline-block
Content aligned with left edge of body
Code with inline-block
<style>
.tooltip {
display: none;
background: white;
border: 1px solid;
}
.tooltip-trigger:hover .tooltip {
display: block;
position: absolute;
}
.tooltip-trigger {
display: inline-block;
}
</style>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Reiciendis illum praesentium quos aspernatur excepturi molestiae quibusdam, deserunt quo voluptas animi.
<a href="/" class="tooltip-trigger">
ToolTip Region
<span class="tooltip">
Some dummy tooltip content
</span>
</a> Lorem ipsum dolor sit amet.
</p>
Code without inline-block
<style>
.tooltip {
display: none;
background: white;
border: 1px solid;
}
.tooltip-trigger:hover .tooltip {
display: block;
position: absolute;
}
</style>
<p>
Lorem ipsum dolor sit amet consectetur, adipisicing elit. Reiciendis illum praesentium quos aspernatur excepturi molestiae quibusdam, deserunt quo voluptas animi.
<a href="/" class="tooltip-trigger">
ToolTip Region
<span class="tooltip">
Some dummy tooltip content
</span>
</a> Lorem ipsum dolor sit amet.
</p>