html - 像整个链接一样在 <a> 和 <span> 下划线

标签 html css twitter-bootstrap twitter-bootstrap-3 glyphicons

我试图用一行强调 <a><span>

我希望所有内容都是带下划线的链接。它在单词和跨度之间留下了一个小空间,但它不应该。

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" >
<a  href="#" role="button">
    Saber mais   
    <span class="glyphicon glyphicon-menu-right size"></span>  
    <span class="glyphicon glyphicon-menu-right size segundoGlyph "></span>
    </a>

编辑 1:当文本大小大于字形时?图标有细线,文本有粗线!

最佳答案

您可以在悬停时添加它,但您需要注意,默认情况下 top:1px 设置为图标,因此您需要将其删除以获得完整的连续线:

a.good .glyphicon {
  top: 0;
}

a:hover .glyphicon {
  text-decoration: underline;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<a href="#" role="button" class="good">
Good one   
<span class="glyphicon glyphicon-menu-right size"></span>  
<span class="glyphicon glyphicon-menu-right size segundoGlyph "></span>
</a>
<br>
<a href="#" role="button">
Bad one   
<span class="glyphicon glyphicon-menu-right size"></span>  
<span class="glyphicon glyphicon-menu-right size segundoGlyph "></span>
</a>

另一种解决方案是让它们内联,因为默认情况下它们是inline-block,如果您引用specification :

Note that text decorations are not propagated to floating and absolutely positioned descendants, nor to the contents of atomic inline-level descendants such as inline blocks and inline tables.

a .glyphicon {
  top: 0;
  display: inline;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<a href="#" role="button">
Saber mais   
<span class="glyphicon glyphicon-menu-right size"></span>  
<span class="glyphicon glyphicon-menu-right size segundoGlyph "></span>
</a>


并解释一下您最初在两个图标之间看到的细线:

Underlines, overlines, and line-throughs are applied only to text (including white space, letter spacing, and word spacing): margins, borders, and padding are skipped

因此,如果您删除任何空格,您将仅在文本下方看到该行:

<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<a href="#" role="button">
Good one<span class="glyphicon glyphicon-menu-right size"></span><span class="glyphicon glyphicon-menu-right size segundoGlyph "></span></a>

更新

正如评论中所指出的,文本和图标之间的不同 font-size 会使下划线不同,因此在这种情况下我们可以依赖边框:

a:hover {
 text-decoration:none!important;
 border-bottom:1px solid
}
.glyphicon {
  font-size:20px;
}
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<a href="#" role="button">
Good one<span class="glyphicon glyphicon-menu-right size"></span><span class="glyphicon glyphicon-menu-right size segundoGlyph "></span></a>

关于html - 像整个链接一样在 <a> 和 <span> 下划线,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48583982/

相关文章:

javascript - 如何根据屏幕分辨率发送完全不同的HTML内容?

html - 当打印多于一页时,它会在两页之间打断表格

css - 是否可以为 "each"primefaces 主题制作自定义 css?

php - 使用 Bootstrap 对 PHP 和 MYSQL 进行分页

css - bootstrap - 按钮组 - 按钮在左侧被切断

html - IE8 中的 float css 页脚

javascript - 这个脚本有什么问题,为什么我没有收到错误?

javascript - Wordpress自定义表单输入检查

html - 如何在图像旁边 float 多个段落

angular - 使用模板中的 Angular 2+ 切换 Bootstrap 单选按钮