38

我想使用如下代码向 Bootstrap 下拉列表中的链接添加一些图标:

<ul>
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Some Dropdown<b class="caret"></b></a>
        <ul class="dropdown-menu">
            <li><i class="icon-arrow-up"></i><a href="#">Up</a></li>
            <li><i class="icon-arrow-down"></i><a href="#">Down</a></li>
            <li><i class="icon-arrow-left"></i><a href="#">Left</a></li>
            <li><i class="icon-arrow-right"></i><a href="#">Right</a></li>
        </ul>
    </li>
</ul>

但是,图标不合适:

下拉问题

我尝试在这个答案中使用解决方案,但它似乎不起作用。有人可以提供解决方案并解释它为什么/如何工作吗?

演示

谢谢!

4

4 回答 4

66

将图标放在锚标签内:

<ul>
    <li class="dropdown">
        <a href="#" class="dropdown-toggle" data-toggle="dropdown">Some Dropdown<b class="caret"></b></a>
        <ul class="dropdown-menu">
            <li><a href="#"><i class="icon-arrow-up"></i> Up</a></li>
            <li><a href="#"><i class="icon-arrow-down"></i> Down</a></li>
            <li><a href="#"><i class="icon-arrow-left"></i> Left</a></li>
            <li><a href="#"><i class="icon-arrow-right"></i> Right</a></li>
        </ul>
    </li>
</ul>


<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<script src="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/js/bootstrap.min.js"></script>
<link href="https://netdna.bootstrapcdn.com/twitter-bootstrap/2.3.1/css/bootstrap-combined.min.css" rel="stylesheet"/>

于 2013-04-11T04:17:52.323 回答
13

习惯定位

定义你 .dropdown-menu li position relative 我定义position absolute

像这样

.dropdown-menu a {
    white-space:normal;
}
.dropdown-menu > li{position:relative;}

.dropdown-menu > li > i{position:absolute;left:0;top:3px;}

现场演示

于 2013-04-11T04:08:46.523 回答
6

将图标放在 Bootstrap v3 的锚标签内(带有来自http://www.FontAwesome.com的图标):

        <ul class="nav navbar-nav">
            <li class="dropdown">
                <a href="#" class="dropdown-toggle" data-toggle="dropdown">A Dropdown <b class="caret"></b></a>
                <ul class="dropdown-menu">
                    <li><a href="#"><i class="fa fa-arrow-up"></i> Up</a></li>
                    <li><a href="#"><i class="fa fa-arrow-down"></i> Down</a></li>
                    <li><a href="#"><i class="fa fa-arrow-left"></i> Left</a></li>
                    <li><a href="#"><i class="fa fa-arrow-right"></i> Right</a></li>
                </ul>
            </li>
        </ul>

示例:http: //jsfiddle.net/9ce3P/

于 2014-02-28T12:55:28.250 回答
0
<ul class="dropdown-menu" role="menu">
    <li role="presentation">
        <a role="menuitem" tabindex="-1" href="javascript:void(0)">
            <span class="pull-right">Edit</span>
            <span class="glyphicon glyphicon-edit pull-left"></span>
            <span class="clearfix"></span>
        </a>
    </li>
    <li role="presentation">
        <a role="menuitem" tabindex="-1" href="javascript:void(0)">
            <span class="pull-right">Delete</span>
            <span class="glyphicon glyphicon-remove pull-left"></span>
            <span class="clearfix"></span>
        </a>
    </li>
</ul>
于 2014-04-19T11:06:10.710 回答