How to stack/overlap more than 2 icons in Font Awesome?

30.9k views Asked by At

How to stack/overlap more than 2 icons in Font Awesome ?

I have managed to stack/overlap 2 icons like this.

<span class="fa-stack fa-lg">
  <i class="fa fa-square-o fa-stack-2x"></i>
  <i class="fa fa-twitter fa-stack-1x"></i>
</span>

http://jsfiddle.net/npLWz/ ref: http://fontawesome.io/examples/#stacked

but when i try to stack/overlap 3 or more icons like this.

<span class="fa-stack fa-3x">
  <i class="fa fa-square-o fa-stack-3x"></i>
  <i class="fa fa-square-o fa-stack-2x"></i>
  <i class="fa fa-square-o fa-stack-1x"></i>
</span>

http://jsfiddle.net/npLWz/1/

Its getting messed up, any idea , how can i fix it ? and get 3 or more icons stacked/overlapped on each other.

3

There are 3 answers

1
Antony Smith On BEST ANSWER

I had a similar issue and solved using some custom CSS.

.icon-stack {
  position: relative;
  display: inline-block;
  width: 2em;
  height: 2em;
  line-height: 2em;
  vertical-align: middle;
}
.icon-stack-1x,
.icon-stack-2x,
.icon-stack-3x {
  position: absolute;
  left: 0;
  width: 100%;
  text-align: center;
}
.icon-stack-1x {
  line-height: inherit;
}
.icon-stack-2x {
  font-size: 1.5em;
}
.icon-stack-3x {
  font-size: 2em;
}

Markup is therefore:

<span class="icon-stack fa-3x">
   <i class="fa fa-{{whatever icon 3}} icon-stack-3x"></i>
   <i class="fa fa-{{whatever icon 2}} icon-stack-2x"></i>
   <i class="fa fa-{{whatever icon 1}} icon-stack-1x"></i>
</span>

I decided rather than override fa-stack I'd duplicate so I can still use the original CSS if required.

You can obviously play around with the font size, line height etc to suit your own requirements.

1
klodoma On

This feature is currently provided by fontawesome.

See: https://fontawesome.com/how-to-use/on-the-web/styling/stacking-icons

0
Kaiser On

Finally, a new feature from Font-Awesome was released and now you can stack more than 2 icons:

See the following link: https://fontawesome.com/how-to-use/on-the-web/styling/layering