gpt4 book ai didi

css - 使用混合线性渐变和径向渐变

转载 作者:行者123 更新时间:2023-11-28 19:18:13 24 4
gpt4 key购买 nike

当悬停在图像上时,我正在尝试使用线性渐变和径向渐变为背景生成一个形状。

我想在悬停时显示以下形状(灰色的不透明度为 0.8):

enter image description here

我已经编写了以下显示线条的 CSS,但我不知道如何使用径向渐变在顶部显示圆形:

background: linear-gradient(70deg, rgba(34, 34, 34, 0.8) 60%, rgba(0,0,0,0) 60%), 
linear-gradient(70deg, rgba(255, 255, 255, 0.8) 80%, rgba(0,0,0,0) 80%),
linear-gradient(70deg, rgba(34, 34, 34, 0.8) 100%, rgba(0,0,0,0) 100%)

最佳答案

我会像下面那样做:

.box {
height:200px;
width:200px;
border:1px solid;
background:
radial-gradient(circle at 60% 80%, transparent 50%,red 51%) top center/60px 60px,
linear-gradient(red,red) top left /calc(50% - 60px/2) 60px,
linear-gradient(red,red) top right /calc(50% - 60px/2) 30px,
linear-gradient(red,red) bottom left /calc(50% - 60px/2 + 8px) calc(100% - 60px),

linear-gradient(to bottom left, transparent 49.5%,red 50%) 78px 100%/35% calc(100% - 60px),
linear-gradient(to top right, transparent 49.5%,red 50%) 100% 29px/35% calc(100% - 60px);
background-repeat:no-repeat;

}
<div class="box"></div>

为了更好地理解,让每个渐变具有不同的颜色以查看拼图

.box {
height:200px;
width:200px;
border:1px solid;
background:
radial-gradient(circle at 60% 80%, transparent 50%,red 51%) top center/60px 60px,
linear-gradient(green,green) top left /calc(50% - 60px/2) 60px,
linear-gradient(blue,blue) top right /calc(50% - 60px/2) 30px,
linear-gradient(yellow,yellow) bottom left /calc(50% - 60px/2 + 8px) calc(100% - 60px),

linear-gradient(to bottom left, transparent 49.5%,purple 50%) 78px 100%/35% calc(100% - 60px),
linear-gradient(to top right, transparent 49.5%,orange 50%) 100% 29px/35% calc(100% - 60px);
background-repeat:no-repeat;

}
<div class="box"></div>

如果您不仅仅局限于使用渐变,您可以结合一些变换和渐变:

.box {
height:200px;
width:200px;
border:1px solid;
position:relative;
overflow:hidden;
}
.box:before {
content:"";
position:absolute;
border-top:50px solid red;
top:-30%;
left:-30%;
right:-30%;
bottom:0;
background:
radial-gradient(farthest-side at bottom, transparent 97%,red 99%) top/20% 15%,
linear-gradient(red,red) left /40% 100%,
linear-gradient(red,red) right /40% 100%;
background-repeat:no-repeat;
transform: rotate(-24deg) translate(14px, 25px);
}
<div class="box"></div>

关于css - 使用混合线性渐变和径向渐变,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57874820/

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