我有一个“丑陋”的字体问题-太棒了,当我把一个图标链接(图标在链接内)在文本前面。通过悬停图标,图标本身将不会得到下划线,但不知何故,文字和图标之间的空间。不知何故,链接中的文本装饰css规则(下划线同时悬停)与这个奇怪的出现空间中来自图标的css规则发生了冲突。
我怎样才能在空间中去掉这些下划线,而最终却没有任何装饰?(如果可能,不向链接元素添加类,也不使用JS)
下面是一个可以帮助您的代码片段。
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<h1>
<a href="#">
<i class="fa fa-wrench"></i>
</a>
Text of Title
</h1>
发布于 2016-09-12 01:23:46
显然,如果将<a>标记和<i>标记写成一行,它们将不会呈现空格。避免这两个元素之间的中断解决了您的问题。
代码片段:
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<h1>
<a href="#"><i class="fa fa-wrench"></i></a>
Text of Title
</h1>
编辑:
通常,如果不更改元素的默认显示值,情况会更好,但在这里,您可以在display: inline-block;标记中使用<a>删除该空间。
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
h1 > a {
display: inline-block;
}<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet" />
<h1>
<a href="#">
<i class="fa fa-wrench"></i>
</a>
Text of Title
</h1>
不一定与问题有关,但我一段时间前就不再使用图标字体,而是采用SVG图标,在我看来,这些图标要好得多。
下面是是一篇关于如何切换的好文章,而下面是则是关于如何使用它们的另一篇文章。
演示:
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
h1 > a {
display: inline-block;
color: purple;
}
.icon {
display: inline-block;
width: 1em;
height: 1em;
stroke-width: 0;
stroke: currentColor;
fill: currentColor;
}
.icon-wrench {
width: 0.939453125em;
}<h1>
<a href="#">
<svg class="icon icon-wrench">
<use xlink:href="#icon-wrench"></use>
</svg>
</a>
Text of Title
</h1>
<svg style="display:none;">
<symbol id="icon-wrench" viewBox="0 0 30 32">
<title>wrench</title>
<path class="path1" d="M6.857 26.286q0-0.464-0.339-0.804t-0.804-0.339-0.804 0.339-0.339 0.804 0.339 0.804 0.804 0.339 0.804-0.339 0.339-0.804zM18.357 18.786l-12.179 12.179q-0.661 0.661-1.607 0.661-0.929 0-1.625-0.661l-1.893-1.929q-0.679-0.643-0.679-1.607 0-0.946 0.679-1.625l12.161-12.161q0.696 1.75 2.045 3.098t3.098 2.045zM29.679 11.018q0 0.696-0.411 1.893-0.839 2.393-2.938 3.884t-4.616 1.491q-3.304 0-5.652-2.348t-2.348-5.652 2.348-5.652 5.652-2.348q1.036 0 2.17 0.295t1.92 0.83q0.286 0.196 0.286 0.5t-0.286 0.5l-5.232 3.018v4l3.446 1.911q0.089-0.054 1.411-0.866t2.42-1.446 1.259-0.634q0.268 0 0.42 0.179t0.152 0.446z"></path>
</symbol>
</svg>
发布于 2016-09-12 00:26:17
如果我正确地理解了你,你想要删除不必要的下划线,并在图标下添加这个下划线。
只需删除a:hover并将其替换为i:hover,就可以了。
a {
text-decoration: none;
}
.fa-wrench:hover {
text-decoration: underline;
}<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<h1>
<a href="#">
<i class="fa fa-wrench"></i>
</a>
Text of Title
</h1>
发布于 2016-09-12 00:29:25
只需删除a:hover并添加.fa-wrench:hover即可。
h1 {
font-size:2.5em;
}
a {
text-decoration: none;
}
.fa-wrench:hover{
text-decoration: underline;
} <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css" rel="stylesheet"/>
<h1>
<a href="#">
<i class="fa fa-wrench"></i>
</a>
Test Title
</h1>
https://stackoverflow.com/questions/39441877
复制相似问题