3

I've the following code which have button with text inside, I want to add to the button also icon from bootstrap (in the left side of the text ) how should I do that ?

The icon is glyphicon glyphicon-plus

<div style="margin-top: 20px">
    <p>
        @Html.ActionLink("New", "Create",
        null new { @class = "Button", @style = "float:right" })
    </p>    
</div> 
<br />
<style type="text/css">
        .CreateButton {
            background: blue
;
            color: white;
            padding: 4px 10px 4px 10px;
            height: 30px;
            width: 60px;
        }


    </style>
<br />
07_05_GuyT
  • 2,787
  • 14
  • 43
  • 88

3 Answers3

5

You can use a button tag instead of input

<button type="submit" class="btn btn-primary">
  <i class="icon-user icon-white"></i> Sign in
</button>
Gagan Gami
  • 10,121
  • 1
  • 29
  • 55
4

use this to insert the icon

<i class="glyphicon glyphicon-plus"></i>

UPDATE : By using the tag , you are automatically inserting the icon in html. For more info look at this GLYPHICONS - bootstrap icon font hex value. Also it is better to use the classes.

Community
  • 1
  • 1
cache
  • 113
  • 1
  • 11
2

The code you posted doesn't really allow me to help you any better, but let's try.

You need to copy all properties of .glyphicon class inside .CreateButton:before {} and add - also there - content property with value of the icon you want to insert. Check glyphicons stylsheet to find out code of the icon you want. The plus sign you're searching for has a value of "\2b".

.CreateButton:before {
    // the part that will be different for each icon
    content: "\e001";
    // copied from .glyphicon class
    position: relative;
    top: 1px;
    display: inline-block;
    font-family: 'Glyphicons Halflings';
    font-style: normal;
    font-weight: 400;
    line-height: 1;
    -webkit-font-smoothing: antialiased;
}

Since this is the accepted answer, I'll add that in some circumstances it might be better to use the answer by user cache.

Maciej Gurban
  • 5,615
  • 4
  • 40
  • 55