10

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

enter image description here

I want to add icon like cog insteaqd of Text like this

enter image description here

I have tried this

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

buts not working

amphetamachine
  • 27,620
  • 12
  • 60
  • 72
user3214546
  • 6,523
  • 13
  • 51
  • 98

3 Answers3

12

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="btn">
    <span class="glyphicon glyphicon-cog"></span>
</button>

Edit: to add the caret in Bootstrap, you use <span class="caret"></span>

So the end result to get a button with a cog and dropdown caret is:

<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: cog button

Thellimist
  • 3,757
  • 5
  • 31
  • 49
JHS
  • 1,423
  • 17
  • 29
  • 1
    Check out this thread, if you are using bootstrap 4 (in which glyphicon font has been removed): https://stackoverflow.com/questions/32612690/bootstrap-4-glyphicons-migration – Greg Holst Jun 21 '19 at 13:07
1
<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

R3tep
  • 12,512
  • 10
  • 48
  • 75
arjun
  • 11
  • 1
0

Just add this span tag

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

See this DEMO

sheshadri
  • 1,207
  • 9
  • 21