Combine two Font Awesome icons
Asked Answered
C

2

12

I'm trying to combine two Font Awesome icons, to create a stack. I'm trying to merge fa-calendar and fa-clock-o icons. This because, I need an icon for date-time.

So, in order to combine them, I tried this:

HTML

<span class="icon-stack">
   <i class="fa fa-calendar icon-stack-3x"></i>
   <i class="fa fa-clock-o icon-stack-1x"></i>
</span>

CSS

.icon-stack {
  position: relative;
  display: inline-block;
  width: 2em;
  height: 5em;
  line-height: 4em;
  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;
}

This is what I get as a result.

enter image description here

But, I want to bring a little bit to right. I don't know how to do that? What can I do to bring it a bit towards right?

Corie answered 15/11, 2016 at 12:49 Comment(1)
fontawesome.com/how-to-use/on-the-web/styling/stacking-icons and then just play with left and top propertiesHainaut
S
8

Well, as you have done your own CSS for position you just need to set the text-align to right, like this:

.icon-stack-3x {
  position: absolute;
  left: 0;
  width: 100%;
  text-align: right;
}

Here is a working example


The problem is, that doesn't look great. So here are a couple of alternatives in case they are of use to you: Example 1, Example 2

Signesignet answered 15/11, 2016 at 12:58 Comment(2)
This works, how can I make it more clear? ie Looks a bit nasty, to make it look good. Any help with that?Corie
@duddosai: Yeah I did try but problem is they don't have a clock icon that isn't transparent (which is the problem). Why don't you try a different calendar? maybe something like this though I did use absolute position which can be problematic sometimes, especially with different browsers. You could try using the built-in stacking classes instead, and do it simple like thisSignesignet
F
0

You can either make clock align right or padding-left by adding a new class Please see the below code:

.icon-stack {
      position: relative;
      display: inline-block;
      width: 2em;
      height: 5em;
      line-height: 4em;
      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;
    }
.right_align { padding-left:5px; }
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.3/css/font-awesome.min.css">
<span class="icon-stack">
   <i class="fa fa-calendar icon-stack-3x"></i>
   <i class="fa fa-clock-o icon-stack-1x right_align"></i>
</span>
Feer answered 15/11, 2016 at 12:57 Comment(1)
This helps, but I want it to look good, like it must be clear. What can be done?Corie

© 2022 - 2024 — McMap. All rights reserved.