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 container?
http://jsbin.com/idudal/24/edit
Ie. this (where drag drag drag
gets cut off):
Should appear as:
HTML:
<span id="test" class="drag-hint"><span>drag drag drag drag drag</span>Hover me</span>
CSS:
.drag-hint {
position:relative;
margin: 50px;
}
.drag-hint > span {
background: black;
color: white;
white-space: nowrap;
display:none;
}
.drag-hint:hover > span {
display: inline;
position:absolute;
top: -25px;
left: 0;
right: 0;
text-align: center;
}
The tooltip text is placed inside an inline element (like <span>) with class="tooltiptext" . CSS: The tooltip class use position:relative , which is needed to position the tooltip text ( position:absolute ). Note: See examples below on how to position the tooltip. The tooltiptext class holds the actual tooltip text.
The solution is to use HTML '<table>' format for tooltip with 'text-align: center'.
The tooltip, also known as infotip or hint, is a common graphical user interface (GUI) element in which, when hovering over a screen element or component, a text box displays information about that element, such as a description of a button's function, what an abbreviation stands for, or the exact absolute time stamp ...
Tooltip is a concept used in HTML for showing some extra information about the specifically selected element. This can be done on the mouse hover effect whenever the user moves the mouse over an element that is using a tooltip to display specified information about that element.
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;
}
<span class="drag-hint">
<span>drag drag drag drag drag</span>
Hover me</span>
<span class="drag-hint">
<span>Lorem ipsum dolor sit amet, consectetur adipisicing elit.</span>
Hover me</span>
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