33

I have a similar problem like here , i want to place font awesome icon into my submit button and also a text, it looks so: http://prntscr.com/608exx

Content of my input submit value is Buy now  

The icon is visible because i set on input field font-family: FontAwesome; my question is, how can i set on my text inside the button standard font family?

Community
  • 1
  • 1
m_73
  • 569
  • 2
  • 5
  • 14

3 Answers3

50

Try

<button type="submit" class="btn btn-default">
                    <i class="fa fa-shopping-cart"></i> Buy Now
                </button>
Society43
  • 737
  • 9
  • 12
2

In order to do this whilst retaining the <input> element, you must put the Font Awesome glyph outside of the <input> and then simply position it on top.

<span><i class="fas fa-shopping-cart glyph"></i></span>
<input type="button" class="button" value="Basket" />

Then simply add some CSS to make the whole button clickable.

.glyph{
    position: relative;
    left: 35px;
    pointer-events: none; //this makes the glyph clickable as part of the input
}

.button{
    width: 100px;
    height: 100px;
    padding-left: 20px;
}

JSFiddle

1

It is quite easy to change it only via CSS. Just need to pick up all types of tags attributes.

For example:

for buttons: input, [type="button"], [type="reset"], [type="submit"] for text: input, [type="text"] and etc...

input, [type="button"], [type="reset"], [type="submit"] {
    -webkit-appearance: button;
    background-color: #EF2B76;
    padding-left: 2rem;
    padding-right: 2rem;
    cursor: pointer;
    color: white;
}

input, [type="text"] {
    background-color: white;
    padding-left: 2rem;
    padding-right: 2rem;
    cursor: pointer;
    color: white;
}
nkrivenko
  • 1,231
  • 3
  • 14
  • 23