【问题标题】:Transform scale slightly nudges Font Awesome icon变换比例略微推动 Font Awesome 图标
【发布时间】:2020-04-16 15:41:51
【问题描述】:

我在带有display: flex 的父div 中有一个Font Awesome 图标,它本身位于display: flex 的容器div 中。

当我在悬停时尝试 transform: scale(1.2) 时,它会稍微推动元素:

https://jsfiddle.net/Daniel_Knights/gptyo3be/5/

.container {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
  height: 100%;
}

.parent {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100px;
  height: 100px;
}

i {
  cursor: pointer;
  transition: transform 0.2s;
}

i:hover {
  transform: scale(1.2);
}
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.13.0/css/all.css">

<div class="container">
  <div class="parent">
    <i class="fa fa-eye" id="single-item-eye"></i>
  </div>
</div>

任何想法为什么会这样?

【问题讨论】:

    标签: html css font-awesome-5


    【解决方案1】:

    改用 SVG 版本就不会出现问题。缩放 SVG 比缩放文本更好:

    .container {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100%;
      height: 100%;
    }
    
    .parent {
      display: flex;
      justify-content: center;
      align-items: center;
      width: 100px;
      height: 100px;
    }
    
    svg {
      cursor: pointer;
      transition: transform 0.2s;
    }
    
    svg:hover {
      transform: scale(1.2);
    }
    <script  src="https://use.fontawesome.com/releases/v5.13.0/js/all.js"></script>
    
    <div class="container">
      <div class="parent">
        <i class="fa fa-eye" id="single-item-eye"></i>
      </div>
    </div>

    相关:Why is text getting blurry and wobbles during 2d scale transform

    【讨论】:

    • 它在小提琴中有效,但由于某种原因在我的网站上无效。除了链接脚本标签还有其他设置吗?
    • 确保删除 CSS 并保留脚本
    • @Daniel_Knights 也清除了你的缓存,也许你还能看到旧的
    • 我已经做到了,它就像在你的小提琴中一样工作,但现在我页面上的所有其他 fontawesome 图标都不起作用
    • @Daniel_Knights 还注意到,使用 SVG 意味着您不再有 而是 svg 标签。检查这个:stackoverflow.com/a/48753896/8620333stackoverflow.com/a/48608619/8620333
    猜你喜欢
    • 2021-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-31
    • 2018-05-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多