html - 如何调整背景颜色的大小并调整其位置?

标签 html css css-transitions background-color

我有一张图片,当我悬停它时,背景颜色会改变,但我想改变大小和位置。

.hoverme:hover {
  background-color: #f7b0ee;
  border-radius: 50%;
  transition: initial 0.5s ease;
}
<div class="col col-md-6">
  <a href="#" onclick="gotofive()">
    <img class="hoverme" style="width: 50%;" src="https://preview.ibb.co/e00h5d/yes_student.png">
  </a>
</div>

我想把它变成这样:

enter image description here

我已经尝试了 background-size,但没有任何反应。

最佳答案

使用radial-gradient代替背景色,您可以轻松控制它的位置和大小:

.hoverme:hover {
  background-image: radial-gradient(#f7b0ee 50%, transparent 51%);
  background-position:0 -20px;
  background-repeat:no-repeat;
  /*border-radius: 50%; no more needed*/
}
<img class="hoverme" style="width: 40%;" src="https://preview.ibb.co/e00h5d/yes_student.png">

如果你想要过渡,试试这个:

.hoverme {
  background-image: radial-gradient(circle at 50% calc(50% - 20px),#f7b0ee 50%, transparent 51%);
  background-position:center;
  background-size:0% 0%;
  background-repeat:no-repeat;
  /*border-radius: 50%; no more needed*/
  transition:all 1s;
}
.hoverme:hover {
  background-size:100% 100%;
}
<img class="hoverme" style="width: 40%;" src="https://preview.ibb.co/e00h5d/yes_student.png">

关于html - 如何调整背景颜色的大小并调整其位置?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50272710/

相关文章:

javascript - HTML数据属性IE6支持

javascript - 使用什么来创建在 apache2 上运行的蜂鸣器 Web 应用程序

html - Font-Awesome 版本 6 图标未显示

css - 将在过渡时更改 css 使用

javascript - 我如何将 CSS 过渡(例如淡入淡出)应用于 React 中的元素列表,以便它们的动画在渲染时一个接一个地排序?

javascript - html5 数字类型只接受正整数

html - CSS Navigation Sprite - 奇怪的形状(不是正方形)

css - 使用变换组合 CSS 动画

javascript - Bootstrap-Navbar 在移动设备上看起来不一样

javascript - 通过 JavaScript 分配时,CSS 转换不起作用