Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 311
user3214546 Avatar asked May 19 '15 06:05

user3214546


People also ask

How do I add icons to Bootstrap 4?

Bootstrap 4 Icons. Bootstrap 4 does not have its own icon library (Glyphicons from Bootstrap 3 are not supported in BS4). However, there are many free icon libraries to choose from, such as Font Awesome and Google Material Design Icons. To use Font Awesome icons, add the following to your HTML page (No downloading or installation is required):

What is the default icon for dropdown button in Bootstrap?

Last Updated : 30 Nov, 2019 Bootstrap provides the option of adding a dropdown to our websites. The default icon on the dropdown button is the ‘downward solid arrow’ logo. Even though it serves its purpose, most of the modern-day websites nowadays use Bootstrap.

What is the best icon library for Bootstrap 4?

Bootstrap 4 does not have its own icon library ( Glyphicons from Bootstrap 3 are not supported in BS4). However, there are many free icon libraries to choose from, such as Font Awesome and Google Material Design Icons.

How to add Font Awesome icon in Bootstrap?

This is necessary because unlike Glyphicon, Font Awesome isn't part of Bootstrap CSS. Create an <i> element to contain your icon (this is a Font Awesome convention).


1 Answers

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

like image 164
JHS Avatar answered Oct 07 '22 23:10

JHS