I know that you can create a custom “tooltip” using selectors :hover:afterand align this tooltip with the source item by marking the source item as position:relativewith the tooltip as absolute.
test
<span custom-tooltip="testing a custom tooltip" class="tooltip">test</span>
test
CSS
.tooltip {
position: relative;
}
.tooltip:hover:after {
content: attr(custom-tooltip);
position: absolute;
background: #000000;
color: white;
}
However, I have to use absolute values to place or size this item :after
top: 30px;
left: -30px;
width: 300px;
What if I want to make the element as wide as it should be (Percentage refers to the parent element creating a large vertical block, so I cannot tell it to go width: 100%)
And centered under the parent ( left: -50%leads to the fact that he moves 50% of the parent to the left, and not in the center)
javascript? ( , - , calc() ?