You need to enable JavaScript to run this app. 如何实现匹配参考图的曲线雾感背景叠加层?
优惠活动
大模型
产品
解决方案
定价
更多

如何实现匹配参考图的曲线雾感背景叠加层?

现有代码的问题点
  • 径向渐变的定位参数circle at -100% 为无效值,无法生成参考图中从左侧实白色块向右自然过渡透明的斜向渐变效果,最终渲染的渐变位置会发生整体偏移。
  • 叠加层未设置和外层容器一致的圆角规则,直角的叠加层会溢出容器的圆角边界。
  • 包裹背景和叠加层的.holder 未设置占满父容器的尺寸,内部元素的定位参照基准不符合预期。
效果实现调整方案

参考图的效果本质是斜向渐变的线性蒙版,之前注释掉的线性渐变思路是正确方向,不需要使用径向渐变,只需要微调渐变角度和色标节点即可匹配效果。

修正后的完整代码:

*,*::after,*::before{
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}
section{
    margin-left: auto;
    padding: 20px 100px;
}
.container{
    position: relative;
    min-width: 100%;
    height: 400px;
    background: rgb(0, 64, 255);
    margin: 20px;
    border-radius: 20px;
    /* 裁剪溢出的子元素,避免圆角边界出现直角溢出 */
    overflow: hidden;
}
.holder{
    width: 100%;
    height: 100%;
    position: relative;
}
.developer-overlay{
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    /* 替换为匹配参考图效果的斜向线性渐变 */
    background: linear-gradient(115deg, 
        rgb(255, 255, 255) 0%,
        rgba(255, 255, 255, 0.8) 35%,
        rgba(255, 255, 255, 0.35) 80%,
        transparent 100%
    );
}
<section>
    <div class="container">
       <div class="holder">
        <div class="developer-bg"></div>
        <div class="developer-overlay"></div>
       </div>
    </div>
</section>

调整提示:如果渐变过渡位置和预期有偏差,可以直接修改linear-gradient的首个角度值,或者调整每个色标对应的百分比数值,直到匹配视觉效果。


内容的提问来源于stack exchange,提问作者نور

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.11.10 10:45:11