I've implemented a basic tooltip feature on my website using the tooltip attribute and an ::after pseudoelement. The issue I'm facing is that the pseudoelement wraps to the size of its parent element because it's positioned outside. Is there a way to prevent this behavior without disabling wrapping completely?
Here is the link to the Fiddle for reference: https://jsfiddle.net/v5zhf2nu/1/
CSS:
[tooltip]
{
position: relative;
cursor: help;
}
[tooltip]::after
{
pointer-events: none;
position: absolute;
content: attr(tooltip);
left: 100%;
top: 50%;
margin-left: 3px;
background-color: #111111;
color: white;
width: auto;
padding: 3px;
border-radius: 3px;
font-size: 12px;
font-weight: normal;
padding-left: 6px;
padding-right: 6px;
display: none;
z-index: 3;
max-width: 1000px;
}
[tooltip]:hover::after
{
display: inline-block;
}
HTML:
<span tooltip = "This is some information! Unfortunately, it seems to want to line break very early.">Mouse over me!</span>