gpt4 book ai didi

html - 将现有的悬停 CSS 类用于其他 html 标签

转载 作者:行者123 更新时间:2023-11-28 05:12:47 25 4
gpt4 key购买 nike

我的一些图片有悬停效果。

目前悬停效果在 figure 标签上处于事件状态。我现在添加了一个 picture 标签。

是否可以从现有 CSS 向 picture 标签添加相同的 CSS,而不必编写整个 CSS,唯一的变化是添加 pciture关闭

  figure{
margin: 0;
padding: 0;
background: #fff;
}
figure:hover+span {
bottom: -36px;
opacity: 1;
}
/* Opacity for banner? */
.hover5 figure img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: 0.8s ease-in-out;
}
.hover5 figure:hover img {
opacity: .5;
}
<div class="hover5 column">
<figure>
<img src="https://placehold.it/425x218" alt="#" class="img-responsive"></img>
</figure>
</div>



<div class="hover5 column">
<picture>
<source media="(min-width: 650px)" srcset="https://placehold.it/300x244"></source>
<source media="(min-width: 320px)" srcset="https://placehold.it/300x320"></source>
<img src="https://placehold.it/300x244" alt="#" style="width:100%;"></img>
</picture>
</div>

最佳答案

您可以使用更通用的选择器来代替 figurepicture:> *。这将以 .hover5 的子元素为目标,无论它是什么元素类型。

.hover5 > *{
margin: 0;
padding: 0;
background: #fff;
}
.hover5 > *:hover+span {
bottom: -36px;
opacity: 1;
}
/* Opacity for banner? */
.hover5 > * img {
opacity: 1;
-webkit-transition: .3s ease-in-out;
transition: 0.8s ease-in-out;
}
.hover5 > *:hover img {
opacity: .5;
}
<div class="hover5 column">
<figure>
<img src="https://placehold.it/425x218" alt="#" class="img-responsive"></img>
</figure>
</div>



<div class="hover5 column">
<picture>
<source media="(min-width: 650px)" srcset="https://placehold.it/300x244"></source>
<source media="(min-width: 320px)" srcset="https://placehold.it/300x320"></source>
<img src="https://placehold.it/300x244" alt="#" style="width:100%;"></img>
</picture>
</div>

关于html - 将现有的悬停 CSS 类用于其他 html 标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51931789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com