[英]CSS span hover not working
I want to show the dotted line when mouse hover the link, this method doesn't work. 我想在鼠标悬停链接时显示虚线,此方法不起作用。
.text-link { color: #446CB3; font-family: "Tahoma"; font-size: 15px; text-decoration:none; } .text-link:hover { text-decoration-style: dotted; }
<a href="URL" target="_blank" data-role="none"> <span class="text-link">Click me</span> </a>
It doesn't look like text-decoration-style: dotted
is supported in all browsers : 它看起来不像
text-decoration-style: dotted
所有浏览器都支持 text-decoration-style: dotted
:
For full support, you could use border-bottom-style: dotted
. 要获得完全支持,可以使用
border-bottom-style: dotted
。
In order for this to work, you need to remove the underline from the anchor element using text-decoration: none
. 为了使其工作,您需要使用
text-decoration: none
从anchor元素中删除下划线。 Then just add a border-bottom
to the element: 然后只需在元素中添加一个
border-bottom
:
a { text-decoration: none; } .text-link { color:#446CB3; font-family:"Tahoma"; font-size:15px; border-bottom: 1px solid; } .text-link:hover { border-bottom-style: dotted; }
<a href="URL" target="_blank" data-role="none"><span class="text-link">Click me</span></a>
Try this. 尝试这个。
HTML: HTML:
<a href="URL" target="_blank" data-role="none"><span class="text-link">Click me</span></a>
CSS: CSS:
.text-link{
color:#446CB3;
font-family: "Tahoma";
font-size:15px;
text-decoration: none;
}
.text-link:hover{
border-bottom: 2px dotted #446CB3;
}
What browser are you using? 你使用的是什么浏览器? The
text-decoration-style
is only supported by Firefox according to W3Schools if you turn off the text-decoration-style
, the hover works fine. 该
text-decoration-style
是由Firefox的按照只支持W3Schools的 ,如果你关闭text-decoration-style
,悬停工作正常。 see this fiddle . 看到这个小提琴 。
This is only supported by firefox, and it required the -moz-
prefix. 这只有firefox支持,它需要
-moz-
前缀。
https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-style https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-style
It should also applied on the a
( or remove it from the a
and apply the full text-decoration
on the span
( 它也应该应用于
a
( 或从a
删除它并在span
上应用text-decoration
(
a { color: #446CB3; font-family: "Tahoma"; font-size: 15px; } a:hover { -moz-text-decoration-style: dotted; }
<a href="URL" target="_blank" data-role="none"> <span class="text-link">Click me</span> </a>
text-decoration-style
is only supported by Firefox 36 (which, at the time of writing, isn't yet released on the stable branch). 只有Firefox 36支持
text-decoration-style
(在编写本文时,尚未在稳定分支上发布)。
For earlier versions of Firefox, you can use the -moz-
prefixed version of the property. 对于早期版本的Firefox,您可以使用该属性的
-moz-
前缀版本。 In other browsers you can only fake it with borders. 在其他浏览器中,您只能使用边框伪造它。
You should also set text-decoration-line
and maybe text-decoration-color
. 您还应该设置
text-decoration-line
和text-decoration-color
。
Also consider using the text-decoration
shorthand property: 还要考虑使用
text-decoration
速记属性:
.text-link:hover {
text-decoration: underline dotted;
}
.text-link { color: #446CB3; font-family: "Tahoma"; font-size: 15px; } .text-link:hover { text-decoration: underline dotted; }
<a href="URL" target="_blank" data-role="none"> <span class="text-link">Click me</span> </a>
However, you will still have anchor's text-decoration
. 但是,您仍然会有锚
text-decoration
。 To prevent anchor's text-decoration
from affecting .text-link
(but not other content that could be in the anchor), you can use 为了防止锚的
text-decoration
影响.text-link
(但不能影响锚中的其他内容),你可以使用
.text-link {
display: inline-block;
}
.text-link { color: #446CB3; font-family: "Tahoma"; font-size: 15px; } .text-link { display: inline-block; } .text-link:hover { text-decoration: underline dotted; }
<a href="URL" target="_blank" data-role="none"> <span class="text-link">Click me</span> </a>
.text-link { color: #446CB3; font-family: "Tahoma"; font-size: 15px; text-decoration:none; } .text-link:hover { text-decoration:underline; text-decoration-style: dotted; }
<a href="URL" target="_blank" data-role="none" > <span class="text-link">Click me</span> </a>
.text-link { color: #446CB3; font-family: "Tahoma"; font-size: 15px; text-decoration:none; } .text-link:hover { text-decoration:underline; text-decoration-style: dotted; }
<a href="URL" target="_blank" data-role="none" class="text-link"> <span>Click me</span> </a>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.