html - Css Transition 未按预期工作

标签 html css

我真的可以在我的 CSS 代码中使用一些帮助。

我正在尝试制作我的 <h1>使用 transition 改变颜色和形状属性(property)。

当我将鼠标悬停在标题上时,我希望形状和颜色缓慢变化, 但目前只有颜色受到影响,形状会独立变化。

我的代码如下:

HTML :

<h1 class="box">Abcdefg</h1>

样式:

.box {
      background: #2db34a;
      margin: 1px auto;
      transition: background 1s linear;
      border-radius: 0.3%;
      color: white;
      cursor: pointer;
      height: 95px;
      line-height: 95px;
      text-align: center;
      width: 400px;
    }

.box:hover {
      background: #ff7b29;
   border-radius: 50%;
}

谢谢。

最佳答案

你只需要添加border-radius到你的transition

.box {
  background: #2db34a;
  margin: 1px auto;
  transition: background 1s linear, border-radius 1s linear;
  border-radius: 0.3%;
  color: white;
  cursor: pointer;
  height: 95px;
  line-height: 95px;
  text-align: center;
  width: 400px;
}

.box:hover {
  background: #ff7b29;
  border-radius: 50%;
}
<h1 class="box">Abcdefg</h1>

关于html - Css Transition 未按预期工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45337699/

相关文章:

html - 页面中间的完美居中按钮

jquery - 列表 : reverse direction 上的鼠标滚轮水平滚动

javascript - jQuery求div可以包含的字符串长度

html - CSS 渐变停止然后重复

html - 标题上的居中对齐按钮(并做出响应)

javascript - 如何编辑我的脚本以定位 div 中的特定 HTML 文本

python - 通过 python 脚本查找 unicode 范围

javascript - 使用 HTML5 canvas 和 Javascript 显示多帧 dicom 图像

javascript 表未放置在 div 中

javascript - 如何延迟加载外部 JS 文件(Google Analytics)?