gpt4 book ai didi

html - CSS:悬停时着色圆形div?只在 div 后面着色?

转载 作者:行者123 更新时间:2023-11-28 05:52:31 24 4
gpt4 key购买 nike

我正在尝试在悬停时为圆形 div 着色(就像保持其原始颜色但在其上添加黑色透明色调一样)。我在一个 div 中有一个 three.js,它位于另一个 div 中以创建循环效果,然后围绕此创建了一个额外的 div:

<ul>
<!-- <li>-->
<div class = "overlay"><a href="polyGalaxy/index.html"><div class ="circle1">
<div id ="btn1"></div>
</div>
</a></div>
<!--</li>
<li>
<div class ="circle2">
<div id ="btn2"></div>
</div>
</li>-->
</ul>

我曾尝试使用此创建色调:

.overlay:hover {
background: rgba(0,0,0,0.5);
border-radius: 50%;
z-index: 5;
}
.circle1 {
background: #50a3a2;
background: -webkit-linear-gradient(top left, #50a3a2 0%, #53e3a6 100%);
background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
display: table;
border-radius: 50%;
position: relative;
margin: 50px auto;
height: 100px;
width: 100px;
}
#btn1 {

vertical-align: middle;
text-align:center;
left:0%;
position:relative; /*makes left effective*/
display:table-cell;
}

然而,overlay 仅在圆形 div 后面着色。我知道这一点是因为当我删除 border-radius 时,我得到了这个: enter image description here

如何在悬停时为圆形 div 着色?

最佳答案

您可以使用伪元素来创建这种效果,该元素具有在悬停时淡出的 rgba 背景颜色(色调):

.circle1 {
background: #50a3a2;
background: -webkit-linear-gradient(top left, #50a3a2 0%, #53e3a6 100%);
background: linear-gradient(to bottom right, #50a3a2 0%, #53e3a6 100%);
display: table;
border-radius: 50%;
position: relative;
margin: 50px auto;
height: 100px;
width: 100px;
}

.circle1::after {
content: '';
position: absolute;
top: 0; left: 0; right: 0; bottom: 0;
background: rgba(0, 0, 0, 0.5);
border-radius: inherit;
display: block;
opacity: 0;
transition: opacity 0.5s;
}

.circle1:hover::after {opacity:1;}
<div class="circle1">
<div id="btn1"></div>
</div>

jsFiddle:https://jsfiddle.net/azizn/9zn3mpa4/

关于html - CSS:悬停时着色圆形div?只在 div 后面着色?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37243639/

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