html - How to resize a background-color and adjust its position?
问题描述
Hello guys i have some problem, i have an image and when i hover it, background color changed and i want to change the size and position.
here is my html
<div class="col col-md-6 hoverme">
<a href="#" onclick="gotofive()">
<img style="width: 70%;" src="assets/images/yes_student.png">
</a>
</div>
and this is my css
.hoverme:hover {
background-color: #f7b0ee;
border-radius: 50%;
transition : initial 0.5s ease;
}
here is the result https://codepen.io/anon/pen/xjWgWx?editors=1000
and i want to make it like this
anyone got suggestion or something? i already try background-size, but nothing happen. thanks for your help
解决方案
使用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">
推荐阅读
- out-of-memory - Hazelcast 分布式地图堆大小控制
- jquery - 如何在 django 模板中循环获取 jQuery datepicker?
- magento - Magento 2 Klarna 结帐
- python - 运行 main 后似乎看不到变量并从 Python IDLE shell 使用它们
- jquery - ajax 查询不等待第一个 ajax 查询执行——我认为
- java - `main` 和 `test` 中的相同包被视为不同
- python - Python - Altair - 带选择的堆积条形图
- java - 如何获取 MaxUploadSizeExceededException 的请求对象
- javascript - 如何修复 Vuejs 中的“webpack Dev Server Invalid Options”
- python - SpeechRecognition 不工作(未检测到麦克风)