【问题标题】:FontAwesome spinning icon misplacedFontAwesome 旋转图标错位
【发布时间】:2018-01-17 12:59:06
【问题描述】:

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

我只是通过创建 .g-im-icon -> .g-im-icon-for-spin 的克隆并使用顶部、左侧和变换样式来解决此问题。

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

.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>

【问题讨论】:

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


【解决方案1】:

在您的 .g-im-icon-c 类中,您可以实现 flexbox 以使其项目居中而不是使用绝对位置,这是因为 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;
  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%);*/
}
<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>

【讨论】:

  • 我总是对你们这些 css 人印象深刻,你们如何能如此快速地解决它,而我则花费数小时尝试这些东西。谢谢!
【解决方案2】:

作为一个选项,您可以尝试将负边距应用于所有旋转图标.fa-spin

.fa-spin {
  margin-left: -25%;
  margin-top: -25%;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-08-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多