twitter-bootstrap - Bootstrap 导航栏中的字体图标使用哪个元素

标签 twitter-bootstrap twitter-bootstrap-3 font-awesome glyphicons font-awesome-4

Bootstrap 3 导航栏使用字形和 Font Awesome 图标,如下面的 html 所示。 Bootstrap手册推荐使用span元素:

            <span class="fa fa-pencil-square-o" aria-hidden="true"></span>

FontAwesome网页推荐使用i元素:

            <i class="fa fa-pencil-square-o" aria-hidden="true"></i>

使用 i 元素使图标比使用 span 更大。越大越好。

字体图标应使用哪个元素?

<div id="sidebar-left" class="col-md-2">
            <div class="navbar-collapse sidebar-nav">
                <ul class="nav nav-tabs nav-stacked main-menu">
                            <li>
            <a href='OpenInvoice'>
                <i class="fa fa-pencil-square-o" aria-hidden="true"></i>
                <span>Invoice</span>
            </a>
        </li>

服务器端采用ASP.NET MVC4。

最佳答案

Using i element makes icon bigger than using span

这个论点没有实际意义,因为 Font-Awesome 的图标是基于字体的,并且可以使用 CSS 的 font-size 手动调整大小。属性(property)。这意味着您可以自己覆盖图标的大小,无论您使用哪个元素。

我应该选择哪个元素?

围绕哪个元素最好使用存在一些争论(参见 Should I use <i> tag for icons instead of <span>? ),但忽略语义,重要的是要注意 Font-Awesome 图标包含在伪元素中(特别是 ::before ) - 所以除非它不支持伪元素(例如 input 元素),使用哪个元素并不重要。

HTML 规范怎么说?

不幸的是,规范没有告诉我们可以使用基于字体的图标做什么,但关键点是:

<span>

The span element doesn't mean anything on its own, but can be useful when used together with the global attributes, e.g. class, lang, or dir. It represents its children.


<i>

The i element represents a span of text in an alternate voice or mood, or otherwise offset from the normal prose in a manner indicating a different quality of text, such as a taxonomic designation, a technical term, an idiomatic phrase from another language, transliteration, a thought, or a ship name in Western texts.

你可以用它做你想做的事。

关于twitter-bootstrap - Bootstrap 导航栏中的字体图标使用哪个元素,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30025683/

相关文章:

ruby-on-rails - 为一页 Bootstrap 网站获取动态事件 li

css - rails : Simple_form on one line?

ios - 如何防止在 ios swift 中 Font Awesome 更改文本

html - 带有 wp_bootstrap_navwalker float 问题的 Bootstrap 菜单

jquery - 使用 Font-Awesome - 在 Chrome 中,通过 <i class ="icon-ok"></i> 标记显示的图标不显示任何样式,也不会触发任何事件

twitter-bootstrap - 字体很棒,输入类型 'submit'

jquery - 具有适当文本对齐的列表样式和元素符号效果

javascript - 隐藏在包含 div 滚动条的下方的 Div 溢出 : scroll set

jquery - 在将 z-index 设置为 -1 时,Bootstrap Carousel 控件无法单击

javascript - 在 Opera 12 中离开文本框时弹出窗口不会隐藏