比例:悬停前

Scale :before when hovering

我试图在悬停时缩放 <span>:before 内容。 到目前为止,悬停时应用了样式,但是没有视觉变化,:before 保持相同的比例。

到目前为止我得到了什么:

<div class="comment-actions">
  <span class="comment-likes icon-ico-heart">
    12
  </span>
</div>

SASS (CSS):

.comment-likes
  transition: all 100ms ease-in-out
  color: #92a3b9
  cursor: pointer

  &:hover::before
    transform: scale(1.5)

Icomoon:

.icon-ico-heart:before {
  content: "\e914";
}

[class^="icon-"], [class*=" icon-"] {
  /* use !important to prevent issues with browser extensions that change fonts */
  font-family: 'icomoon' !important;
  speak: none;
  font-style: normal;
  font-weight: normal;
  font-variant: normal;
  text-transform: none;
  line-height: 1;

  /* Better Font Rendering =========== */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

不要用比例变换属性而是用font-size。所以:

.icon-ico-heart:hover:before {
    font-size: 20px;
}

增加悬停时的 font-size 并向其添加 transition 属性。

.icon-ico-heart:before {
    font-size: 10px;
    -webkit-transition: all 0.3s ease;
    -moz-transition: all 0.3s ease;
    -o-transition: all 0.3s ease;
    -ms-transition: all 0.3s ease;
    transition: all 0.3s ease;
}

.icon-ico-heart:hover:before {
    font-size: 15px;
}

您可以只使用 transition: font 0.3s ease; 为字体应用过渡而不是 all

您可能无法使用字体或图标字体的比例 属性,

您可以使用字体大小 属性。

您无法转换 ::before 元素,因为它的显示类型是:display: inline, 您必须将其更改为 display: inline-block 或其他。

.icon-ico-heart:before {
  content: "\e914";
  display:inline-block;
}