简体   繁体   中英

Override Font Awesome icon whit background image

I'm trying to override/replace Font Awesome icon with background image. I have only CSS access.

What I have: 加按钮

.btn.btn-default.bootstrap-touchspin-up:before {
    font-family: Fontawesome;
    content: "\f067";
    font-size: 14px;
}

What I'm trying to achieve: 加2

.btn.btn-default.bootstrap-touchspin-up:before {
    background-image : url(Images/arrows-left-right.png);
    font-family: initial;
    content: "";
    font-size: 14px;
    height: 20px;
    width: 20px;
}

You need these additional properties

  width: 15px;
  height: 15px;
  display: inline-block; 
  background-position: center;
  background-size: contain;

as mentioned by @Alexander De Sousa in comments, inline-block is much better choice to keep everything inline.

Try this

HTML:

    <span class="btn btn-default"></span>

CSS:

.btn:before {
  font-family: Fontawesome;
  content: "\f067";
  font-size: 14px;
}

.btn {
  border-radius: 50%;
  border: 2px solid black;
}

Demo : http://jsfiddle.net/GCu2D/5181/

display:inline-block;

That's all you need. As standard :before and :after are inline, so they'll collapse in regardless of height and width. Inline-block will get you what you want.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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