How do I change the styling of the title attribute in the following tag without using javascript or CSS, since I am inserting the HTML into a specific spot in an otherwise uneditable doc.
<span title = "This is information"> This is a test
</span>
You can't style an actual title attribute How the text in the title attribute is displayed is defined by the browser and varies from browser to browser. It's not possible for a webpage to apply any style to the tooltip that the browser displays based on the title attribute.
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.
You can't. You'd need to make a custom tooltip to do that. There are libraries for that if you don't want to roll your own.
https://jsfiddle.net/LvjaxLfn/153/
<span aria-label="This is information">This is a test</span>
span:hover {
position: relative;
}
span[aria-label]:hover:after {
content: attr(aria-label);
padding: 4px 8px;
position: absolute;
left: 0;
top: 100%;
white-space: nowrap;
z-index: 20;
background:red;
}
Using an aria label to keep accessibility
You could also add a transition delay to make it show up after a delay like a native html title
https://jsfiddle.net/f9zna6k2/10/
span {
position: relative;
cursor: pointer;
}
span[aria-label]:after {
opacity:0;
content: attr(aria-label);
padding: 4px 8px;
position: absolute;
left: 0;
top: 100%;
white-space: nowrap;
z-index: 20;
background:red;
transition: opacity 0.5s;
pointer-events:none;
}
span[aria-label]:hover:after {
opacity:1;
transition-delay:1.5s;
}
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