html - 在 span 中对之前的字体大小进行动画处理并保持 span 文本的位置

标签 html css transition font-size

我有一个点赞按钮,由 <span> 组成用心(字体图标)作为:before .当 :hover:active状态处于事件状态,:before的字体大小增加(带有过渡)。

现在的问题是:跨度文本改变了位置。 我宁愿让它留在同一个地方。

正常状态:

enter image description here

悬停状态:

enter image description here

事件状态(点击):

enter image description here

HTML:

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

SASS:

.comment-likes
  user-select: none
  color: #92a3b9
  cursor: pointer

  &:before
    +transition(font 100ms linear, color 100ms linear)

  &:hover::before
    font-size: 13px
    color: lighten($main-color, 15%)

  &:active::before
    font-size: 20px
    color: $main-color

  &.active
    color: $main-color

    &:hover::before
      color: $main-color

最佳答案

.comment-likes {
  -webkit-user-select: none;
  user-select: none;
  display: inline-block;
  color: hsl(213, 21%, 72%);
  cursor: pointer;
  font: 11px/1 sans-serif;
}

.comment-likes:before {
  font: normal normal normal 11px/1 FontAwesome;
  content: "\f004";
  margin-right: 4px;
  
  display:inline-block; /* in order to allow CSS3 transform scale */
  transition: 0.3s;
}

.comment-likes:hover:before {
  transform: scale(1.3);
  color: hsl(213, 51%, 62%);
}

.comment-likes:active:before {
  transform: scale(1.5);
  color: hsl(213, 71%, 50%);
}
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.3.0/css/font-awesome.min.css">

<span class="comment-likes">12</span>

关于html - 在 span 中对之前的字体大小进行动画处理并保持 span 文本的位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40257306/

相关文章:

jquery - 在 IE9 中复制 CSS3 动画

javascript - 动画模式无法正常工作

HTML/CSS - 不会消失的神秘顶部填充

html - CSS 如何让位置绝对子级在父级之外可见并溢出 : hidden;

javascript - D3 转换在 "background-color"上工作但不在 "width"上工作

html - 如何同时在框上悬停和过渡?只使用 css 和 html

html - float 到页面底部(不是视口(viewport))的可变高度页脚的 CSS

javascript - 使用 JavaScript 更改文本框背景颜色

html - 图像大小应该在 img 标签的高度/宽度属性中定义还是在 CSS 中定义?

Android webview 和 Twitter bootstrap 修复 navbar 无法点击