如何在不使用JavaScript或CSS的情况下更改以下标签中标题属性的样式,因为我将HTML插入到一个其他无法编辑的文档中的特定位置。
<span title = "This is information"> This is a test
</span>
<span title = "This is information"> This is a test
</span>
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;
}
使用aria标签以保持可访问性
您还可以添加过渡延迟,使其在延迟后显示,就像本地HTML标题一样。
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;
}