Expanding on Pure CSS: Center Tooltip Above Text On Hover -- how does one make the tooltip hover centered relative to its container if the tooltip is wider than said
Here's the simplest solution using CSS3 transform.
JSfiddle Demo
.drag-hint {
position: relative;
margin: 50px;
display: inline-block;
padding: 0 1em;
border: 1px solid red;
/* for visual reference */
}
.drag-hint > span {
background: black;
color: white;
white-space: nowrap;
display: none;
}
.drag-hint:hover > span {
display: inline-block;
position: absolute;
top: -25px;
left: 50%;
transform: translateX(-50%);
text-align: center;
}
drag drag drag drag drag
Hover me
Lorem ipsum dolor sit amet, consectetur adipisicing elit.
Hover me