3

我试图通过接管样式表来模仿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>

4

2 回答 2

2

在您的 .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>

于 2018-01-17T13:08:01.737 回答
1

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

.fa-spin {
  margin-left: -25%;
  margin-top: -25%;
}
于 2018-01-17T13:07:57.757 回答