【问题标题】:Using mixed linear-gradient and radial gradient使用混合线性梯度和径向梯度
【发布时间】:2020-01-12 10:46:30
【问题描述】:

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

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

我编写了以下显示线条的 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%)

【问题讨论】:

    标签: css css-shapes linear-gradients radial-gradients


    【解决方案1】:

    我会这样做:

    .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>

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-04-23
      • 1970-01-01
      • 1970-01-01
      • 2015-08-05
      • 1970-01-01
      • 2013-11-17
      • 2019-07-24
      • 2021-11-16
      相关资源
      最近更新 更多