简体   繁体   English

从工具提示中删除下划线和链接

[英]Remove underline and link from tooltip

I try to implement a tooltip with picture. 我尝试用图片实现工具提示。 That works. 这样可行。 But I have 2 problems: 但是我有两个问题:

  1. If I move mouse over word TooltipText only a dashed line should be displayed. 如果我将鼠标移到TooltipText一词上,则只应显示一条虚线。 But the word is also underlined (because Link). 但是这个词也带有下划线(因为链接)。
  2. I would like to disable the link, since it is a tooltip. 我想禁用该链接,因为它是一个工具提示。 The CSS attribute 'pointer-events: none;' CSS属性'pointer-events:none;' disables the link, but then the tooltip is not working. 禁用链接,但是工具提示不起作用。

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>标记。

  1. The .dotted class is being applied to the 'strong' element, this does not have a text-decoration property. .dotdot类将被应用到'strong'元素,它没有文本装饰属性。 You need to apply a class to the 'a href="#"' tag and set the text-decoration: none; 您需要将一个类应用于'a href =“#”'标记并设置文本修饰:none; on that element. 在那个元素上。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM