[英]Remove underline and link from tooltip
I try to implement a tooltip with picture. 我尝试用图片实现工具提示。 That works.
这样可行。 But I have 2 problems:
但是我有两个问题:
HTML: HTML:
<div class="col-lg-4">
<a href="#">
<div class="hover-img"><strong class="dotted">TooltipText</strong><span><img src="https://via.placeholder.com/350x150"/></span></div>
</a>
</div>
CSS: CSS:
a .hover-img {
position:relative;
}
a .hover-img span {
position:absolute; left:-9999px; top:-9999px; z-index:9999;
border: 2px solid #000;
}
a:hover .hover-img span {
top: 40px;
left: 0;
}
.dotted {
color: #4e555b;
border-bottom: 2px dashed #4e555b;
text-decoration: none!important;
}
.dotted:hover {
text-decoration: none!important;
}
JSFiddle: 的jsfiddle:
https://jsfiddle.net/kdzb108h/ https://jsfiddle.net/kdzb108h/
Add this: 添加:
a {
text-decoration: none;
}
text-decoration
should be applied directly to <a>
, not to its child tags. text-decoration
应直接应用于<a>
,而不应应用于其子标记。
Refer to: https://jsfiddle.net/ewtysb4c/ 请参阅: https : //jsfiddle.net/ewtysb4c/
The word is underlined because the <a>
tag has a href
attribute. 该单词带有下划线是因为
<a>
标记具有href
属性。 If you remove the attribute, both the underline will disappear and the link will be disabled. 如果删除该属性,则两个下划线都将消失并且链接将被禁用。
However, the cursor will also not behave like a link. 但是,光标也不会像链接一样。 You could enforce the
text-decoration: none
in the <a>
tag and add a cursor: pointer
to the the a:hover
rules. 您可以在
<a>
标记中强制执行text-decoration: none
,并添加a:hover
规则的cursor: pointer
。 I'd suggest you create an a.tooltip-link
class and add these styles to it so they won't be applied to all <a>
tags in your page. 我建议您创建一个
a.tooltip-link
类并向其中添加这些样式,这样它们就不会应用于您页面中的所有<a>
标记。
So, first of all want to explaint few things. 因此,首先要解释一些事情。 You used as container, what's wrong.
您用作容器,出了什么问题。 If you see any year w3.org documentation, you'll see that link is inline document.
如果您看到任何年份的w3.org文档,您将看到该链接为嵌入式文档。 This link here: https://www.w3.org/TR/html401/struct/global.html#h-7.5.3 says, that inline elements can contain only other inline elements or text.
这里的链接: https : //www.w3.org/TR/html401/struct/global.html#h-7.5.3说,内联元素只能包含其他内联元素或文本。 Second thing.
第二件事。 I'd rather make the structure next way:
我宁愿采用这种结构:
<div class="wrapper objects">
<div class="object">
<p class="tooltip-provoke">Tooltip Text</p>
<div class="tooltip-text">
<img src="https://via.placeholder.com/350x150"/>
</div>
</div>
</div>
Than set div.tooltip-text display:block
, and change it by hovering p.tooltip-provoke
. 比设置div.tooltip-text
display:block
,并通过将p.tooltip-provoke
悬停进行更改。 By using + in css ('.a + .b') you say to apply styles to first element after element with class="a" and only if it's class="b". 通过在CSS('.a + .b')中使用+,您可以说是将样式应用于class =“ a”且仅当class =“ b”之后的第一个元素。 You can see example here: https://jsfiddle.net/0pmknx4g/9/
您可以在此处查看示例: https : //jsfiddle.net/0pmknx4g/9/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.