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