html - 如何不只旋转图像周围的边框?
问题描述
我正在处理我的项目,并且添加了带边框的图像。我在悬停时旋转边框,但问题是图像也在旋转。
#circle1 {
width: 210px;
height: 210px;
background-color: transparent;
border-radius: 100%;
border: 6px solid #337AB7;
border-left: 6px solid transparent;
overflow: hidden;
transform: rotate(50deg);
transition: linear 2s;
}
#circle1 .elementor-widget-container {
transform: rotate(-50deg);
background-color: transparent;
border-radius: 100%;
overflow: hidden;
transition: linear 2s;
}
#circle1:hover {
transform: rotate(410deg);
transition: linear 2s;
}
#circle1 .elementor-widget-container:hover {
transform: rotate(-410deg);
transition: linear 2s;
}
#circle1 img {
display: block;
}
<div id="circle1">
<div class="elementor-widget-container">
<div class="elementor-image">
<img src="https://i.ibb.co/WkdnS0f/BIcon-1.png" class="attachment-large size-large">
</div>
</div>
</div>
在此,悬停图像也在旋转,但我不想旋转图像,只有边框应该旋转。
只需经常将鼠标悬停在图像上,您就会看到图像也在旋转。
任何帮助深表感谢。
解决方案
更改此选择器
#circle1 .elementor-widget-container:hover
到
#circle1:hover .elementor-widget-container
#circle1 {
width: 210px;
height: 210px;
background-color: transparent;
border-radius: 100%;
border: 6px solid #337AB7;
border-left: 6px solid transparent;
overflow: hidden;
transform: rotate(50deg);
transition: linear 2s;
}
#circle1 .elementor-widget-container {
transform: rotate(-50deg);
background-color: transparent;
border-radius: 100%;
overflow: hidden;
transition: linear 2s;
}
#circle1:hover {
transform: rotate(410deg);
transition: linear 2s;
}
#circle1:hover .elementor-widget-container {
transform: rotate(-410deg);
transition: linear 2s;
}
#circle1 img {
display: block;
}
<div id="circle1">
<div class="elementor-widget-container">
<div class="elementor-image">
<img src="https://i.ibb.co/WkdnS0f/BIcon-1.png" class="attachment-large size-large">
</div>
</div>
</div>
通过使用伪元素,您可以使 HTML 和 CSS 变得更加简单。
#circle1 {
position: relative;
}
#circle1::after {
content: "";
display: block;
width: 210px;
height: 210px;
background-color: transparent;
border-radius: 100%;
border: 6px solid #337AB7;
border-left: 6px solid transparent;
transform: rotate(50deg);
transition: linear 2s;
position: absolute;
top: -6px;
left: -6px;
}
#circle1:hover::after {
transform: rotate(410deg);
transition: linear 2s;
}
<div id="circle1">
<img src="https://i.ibb.co/WkdnS0f/BIcon-1.png" class="attachment-large size-large">
</div>
推荐阅读
- css - 如何将宽度设置为当前路由器插座的 100%?
- c# - 如何首先在两个表 asp.core 代码之间建立关系
- docker - 如何暂停运行 luigi 的 docker 容器?
- .htaccess - 如何在不更改 url 的情况下重定向到错误页面
- ios - 正在添加下载任务
- c# - c# wsdl 签名或解密无效
- javascript - JQuery:仅当所选元素是第一个(占位符)时,才将所有选择元素设置为斜体
- c - 如何解决在 TrueSTUDIO for STM32 中设置断点时出现“断点安装失败:报价不匹配”的问题
- java - Facebook登录后从会话中获取用户ID
- sql-server - 数据库中已经有一个名为 I_XXXRECID 的对象