FontAwesome旋转图标放错了地方

时间:2018-01-17 12:59:06

标签: html css font-awesome font-awesome-5

我试图模仿左边的图标 - 右边的文字"来自https://fontawesome.com/的框通过接管样式表。一切正常,直到我将fa-spin应用于图标(参见示例)。然后图标被错放并且不居中。

我只是通过创建.g-im-icon - >的克隆来解决问题。 .g-im-icon-for-spin并使用top,left和transform样式进行游戏。

然而我想知道是否会有适用于旋转和非旋转图标的通用解决方案?



.g-im-item {
  border-radius: .25rem;
  box-shadow: 0 0.25rem 0.125rem 0 rgba(33, 37, 41, .05);
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

.g-im-icon-c {
  width: 25%;
  font-size: 1.95312rem;
  position: relative;
}

.g-im-text-c {
  padding: 1.5rem;
  width: 75%;
}

.g-im-title {
  font-family: fa5-proxima-nova, Helvetica Neue, Helvetica, Arial, sans-serif;
  margin-top: 0;
  margin-bottom: .5rem;
  font-weight: 600;
}

.g-im-message {
  margin-top: 0;
  margin-bottom: 0;
  line-height: 1.5;
}

.g-im-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

<link href="https://use.fontawesome.com/releases/v5.0.4/css/all.css" rel="stylesheet" />

<div class="g-im-item  k-info-colored">
  <div class="g-im-icon-c">
    <i class="g-im-icon fas fa-tachometer-alt fa-2x"></i>
  </div>
  <div class="g-im-text-c">
    <h3 class="g-im-title">Title goes here</h3>
    <p class="g-im-message">Test goes here</p>
  </div>
</div>


<div class="g-im-item  k-info-colored">
  <div class="g-im-icon-c">
    <i class="g-im-icon fas fa-tachometer-alt fa-spin fa-2x"></i>
  </div>
  <div class="g-im-text-c">
    <h3 class="g-im-title">Title goes here</h3>
    <p class="g-im-message">Test goes here</p>
  </div>
</div>
&#13;
&#13;
&#13;

2 个答案:

答案 0 :(得分:1)

在你的.g-im-icon-c类中你可以实现flexbox以使其项目居中而不是使用position绝对位置,这是因为转换属性会被动画覆盖..这就是为什么你的动画不是& #39; t居中......

&#13;
&#13;
.g-im-item {
  border-radius: .25rem;
  box-shadow: 0 0.25rem 0.125rem 0 rgba(33, 37, 41, .05);
  margin-bottom: 1.5rem;
  display: flex;
  flex-direction: row;
  flex-wrap: nowrap;
}

.g-im-icon-c {
  width: 25%;
  font-size: 1.95312rem;
  display: flex;
    justify-content: center;
    align-items: center;
}

.g-im-text-c {
  padding: 1.5rem;
  width: 75%;
}

.g-im-title {
  font-family: fa5-proxima-nova, Helvetica Neue, Helvetica, Arial, sans-serif;
  margin-top: 0;
  margin-bottom: .5rem;
  font-weight: 600;
}

.g-im-message {
  margin-top: 0;
  margin-bottom: 0;
  line-height: 1.5;
}

.g-im-icon {
  /*position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);*/
}
&#13;
<link href="https://use.fontawesome.com/releases/v5.0.4/css/all.css" rel="stylesheet" />

<div class="g-im-item  k-info-colored">
  <div class="g-im-icon-c">
    <i class="g-im-icon fas fa-tachometer-alt fa-2x"></i>
  </div>
  <div class="g-im-text-c">
    <h3 class="g-im-title">Title goes here</h3>
    <p class="g-im-message">Test goes here</p>
  </div>
</div>


<div class="g-im-item  k-info-colored">
  <div class="g-im-icon-c">
    <i class="g-im-icon fas fa-tachometer-alt fa-spin fa-2x"></i>
  </div>
  <div class="g-im-text-c">
    <h3 class="g-im-title">Title goes here</h3>
    <p class="g-im-message">Test goes here</p>
  </div>
</div>
&#13;
&#13;
&#13;

答案 1 :(得分:0)

作为一种选择,您可以尝试对所有旋转图标.fa-spin

应用负边距
.fa-spin {
  margin-left: -25%;
  margin-top: -25%;
}