Mic*_*ehr 4 html css text-decorations font-awesome
当我在文本前面放置图标链接(链接内的图标)时,我遇到了字体真棒的“丑陋”问题。通过悬停图标,图标本身不会带有下划线,而是文本和图标之间的空间。不知何故,来自链接的文本装饰 css 规则(悬停时下划线)与来自这个奇怪出现空间中的图标的规则相冲突。
怎么才能去掉空间中的这条下划线,最后一点装饰都没有呢?(如果可能,既不向链接元素添加类,也不使用 JS)
这是一个可以帮助您的代码片段。
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
显然<a>,<i>如果您将它们写在一行中,您的标签和您的标签将不会呈现空格。避免这两个元素之间的换行可以解决您的问题。
代码片段:
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
通常,如果您不更改元素的默认显示值会更好,但在这里您可以display: inline-block;在<a>标签中使用以删除该空间。
a {
text-decoration: none;
}
a:hover {
text-decoration: underline;
}
h1 > a {
display: inline-block;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
不一定与问题有关,但我不久前停止使用图标字体并采用了 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;
}Run Code Online (Sandbox Code Playgroud)
<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>Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7927 次 |
| 最近记录: |