在悬停时旋转父级而不是子级

编程入门 行业动态 更新时间:2024-10-10 05:18:21
本文介绍了在悬停时旋转父级而不是子级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

<figure>元素应在悬停时旋转,但其子元素<img>不应该旋转.仅使用SCSS. <figure>的背景略大于<img>的背景,因此具有边框效果.

The <figure> element should rotate on hover but not its child, the <img>. Using SCSS only. <figure> has a background slightly bigger than <img> so it gives a border effect.

.about__image { margin: 4rem; width: 27rem; height: 27rem; float: left; -webkit-shape-outside: circle(50% at 50% 50%); shape-outside: circle(50% at 50% 50%); -webkit-clip-path: circle(50% at 50% 50%); clip-path: circle(50% at 50% 50%); position: relative; background-image: radial-gradient(at left top, red 25%, blue 55%); } .about__photo { position: absolute; margin: 1rem; width: 25rem; height: 25rem; float: left; -webkit-shape-outside: circle(50% at 50% 50%); shape-outside: circle(50% at 50% 50%); -webkit-clip-path: circle(50% at 50% 50%); clip-path: circle(50% at 50% 50%); } div { height: 600px; width: 100vw; background: #eee; } div:hover .about__image{ transform: rotate(90deg); }

<div> <figure class="about__image"> <img src="lorempixel/200/200/" class="about__photo"> </figure> </div>

<figure>元素应在悬停时旋转,但其子元素<img>不应该旋转.仅使用SCSS. <figure>的背景略大于<img>的背景,因此具有边框效果. <figure>元素应在悬停时旋转,但其子元素<img>不应该旋转.仅使用SCSS. <figure>的背景略大于<img>的背景,因此具有边框效果.

The <figure> element should rotate on hover but not its child, the <img>. Using SCSS only. <figure> has a background slightly bigger than <img> so it gives a border effect. The <figure> element should rotate on hover but not its child, the <img>. Using SCSS only. <figure> has a background slightly bigger than <img> so it gives a border effect.

推荐答案

一个想法是旋转容器并将反向旋转应用于图像,如下所示:

An idea is to rotate the container and apply the inverse rotation to the image like this:

.about__image { margin: 4rem; width: 27rem; height: 27rem; float: left; -webkit-shape-outside: circle(50% at 50% 50%); shape-outside: circle(50% at 50% 50%); -webkit-clip-path: circle(50% at 50% 50%); clip-path: circle(50% at 50% 50%); position: relative; background-image: radial-gradient(at left top, red 25%, blue 55%); transition:1s; } .about__photo { position: absolute; margin: 1rem; width: 25rem; height: 25rem; float: left; -webkit-shape-outside: circle(50% at 50% 50%); shape-outside: circle(50% at 50% 50%); -webkit-clip-path: circle(50% at 50% 50%); clip-path: circle(50% at 50% 50%); transition:1s; } div:hover .about__image{ transform:rotate(180deg); } div:hover .about__photo{ transform:rotate(-180deg); } div { height: 600px; width: 100vw; background: #eee; }

<div> <figure class="about__image"> <img src="lorempixel/200/200/" class="about__photo"> </figure> </div>

更多推荐

在悬停时旋转父级而不是子级

本文发布于:2023-11-23 04:20:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1620066.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:而不是

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!