简体   繁体   English

如何添加图标到引导下拉列表

[英]How can i add icon to bootstrap dropdown

I have this code 我有这个代码

        <div class="btn-group" dropdown>
            <button type="button" class="btn btn-danger">Action</button>
            <button type="button" class="btn btn-danger dropdown-toggle" dropdown-toggle>
                <span class="caret"></span>
                <span class="sr-only">Split button!</span>
            </button>
            <ul class="dropdown-menu" role="menu">
                <li><a href="#">Action</a></li>
                <li><a href="#">Another action</a></li>
                <li><a href="#">Something else here</a></li>
                <li class="divider"></li>
                <li><a href="#">Separated link</a></li>
            </ul>
        </div>

which looks like 看起来像

在此输入图像描述

I want to add icon like cog insteaqd of Text like this 我想像这样添加像文本的cog insteaqd这样的图标

在此输入图像描述

I have tried this 我试过这个

<button type="button" class="glyphicon glyphicon-cog"></button>

buts not working 但没有工作

For a button, the icon needs to go inside the button as the button's contents, so instead of <button type="button" class="glyphicon glyphicon-cog"></button> it should be 对于一个按钮,图标需要作为按钮的内容进入按钮内部,因此它应该是<button type="button" class="glyphicon glyphicon-cog"></button>而不是

<button type="button" class="btn">
    <span class="glyphicon glyphicon-cog"></span>
</button>

Edit: to add the caret in Bootstrap, you use <span class="caret"></span> 编辑:要在Bootstrap中添加插入符号,请使用<span class="caret"></span>

So the end result to get a button with a cog and dropdown caret is: 因此,获得带有cog和dropdown插入符号的按钮的最终结果是:

<button type="button" class="btn">
    <span class="glyphicon glyphicon-cog"></span><span class="caret"></span>
</button>

When I paste that code into Bootstrap's homepage, I get this: 当我将该代码粘贴到Bootstrap的主页时,我得到了这个: cog按钮

<div class="btn-group" dropdown>
    <button type="button" class="btn btn-danger"><span class="glyphicon glyphicon-cog"></span></button>
    <button type="button" class="btn btn-danger dropdown-toggle" dropdown-toggle>
        <span class="caret"></span>
        <span class="sr-only">Split button!</span>
    </button>
    <ul class="dropdown-menu" role="menu">
        <li><a href="#">Action</a></li>
        <li><a href="#">Another action</a></li>
        <li><a href="#">Something else here</a></li>
        <li class="divider"></li>
         <li><a href="#">Separated link</a></li>
    </ul>
</div>

You can use this code 您可以使用此代码

Just add this span tag 只需添加此span标记即可

<span class="glyphicon glyphicon-cog" aria-hidden="true"></span>

See this DEMO 看这个DEMO

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM