【问题标题】:Expand width of circle扩大圆的宽度
【发布时间】:2017-02-16 17:48:37
【问题描述】:

我对 CSS3 动画还很陌生,我想知道您如何执行以下操作: 我有一个圆圈:


在悬停时,我想扩大圆圈的宽度使其变成药丸形状,并带有如下图所示的过渡:

这是我尝试过的。问题是随着宽度的扩大,圆会变成椭圆:

.logo {
  background: red;
  width: 100px;
  height: 100px;
  border-radius: 50%;
  transition: width 2s;
}

.logo:hover {
  width: 300px;
}
<div class="logo"></div>

【问题讨论】:

    标签: css css-transitions css-animations css-shapes


    【解决方案1】:

    您只需将边框半径值更改为百分比以外的任何其他单位(列出的所有单位here)。有关其工作原理以及为什么需要将这些单位用于所需输出的说明,请参阅Border-radius in percentage (%) vs pixels (px)

    以 px 为例。 悬停时圆圈扩大为药丸形状

    .logo {
      width: 100px;
      height: 100px;
      border-radius: 50px;
      background: red;
      transition: width 2s;
    }
    .logo:hover {
      width: 300px;
    }
    <div class="logo"></div>

    如果你不知道圆圈的高度,你可以设置一个很高的值,这样圆圈在宽度扩大时保持它的药丸形状:

    .logo {
      width: 200px;
      height: 200px;
      border-radius: 999px;
      background: red;
      transition: width 2s;
    }
    .logo:hover {
      width: 400px;
    }
    <div class="logo"></div>

    【讨论】:

    • 简单而精彩+1
    • 如果尺寸未知,使用大单位(如in)可能会产生更大的长度和更小的数字。
    猜你喜欢
    • 1970-01-01
    • 2014-06-27
    • 2015-08-04
    • 2014-09-12
    • 1970-01-01
    • 2018-01-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多