You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何在Tailwind CSS中实现径向渐变与波浪形边框?

实现Tailwind CSS径向渐变+波浪形底部边框的方案

一、解决径向渐变缺失问题

Tailwind默认没有预设bg-radial-gradient类,直接用自定义背景语法就能实现,两种方式可选:

  • 直接写内联自定义类:
    <div class="bg-[radial-gradient(ellipse_at_center,_var(--tw-gradient-stops))] from-blue-400 via-purple-500 to-pink-500">
      <!-- 容器内容 -->
    </div>
    
  • 配置tailwind.config.js预设复用类:
    /** @type {import('tailwindcss').Config} */
    module.exports = {
      theme: {
        extend: {
          backgroundImage: {
            'radial-custom': 'radial-gradient(ellipse at center, #3b82f6 0%, #8b5cf6 50%, #ec4899 100%)',
          },
        },
      },
    }
    
    之后直接使用bg-radial-custom类即可。

二、实现自然波浪形底部边框

单纯圆角无法达到参考图的波浪效果,推荐两种实用方案:

方法1:伪元素+径向渐变平铺

通过伪元素生成波浪单元并平铺,配合遮罩实现自然过渡:

<div class="relative overflow-hidden bg-[radial-gradient(ellipse_at_center,_var(--tw-gradient-stops))] from-blue-400 via-purple-500 to-pink-500">
  <!-- 内容区域 -->
  <div class="p-8 text-white">
    带径向渐变和波浪边框的容器
  </div>
  <!-- 底部波浪伪元素 -->
  <div class="absolute bottom-0 left-0 w-full h-12 bg-white [mask-image:linear-gradient(to_bottom,rgba(0,0,0,1),rgba(0,0,0,0))]">
    <div class="absolute inset-0 bg-[radial-gradient(120px_120px_at_50%_0%,rgba(255,255,255,1)_45%,transparent_50%)]" style="background-size: 120px 100%"></div>
  </div>
</div>

调整background-size的数值可以改变波浪的密度和大小。

方法2:clip-path自定义裁剪路径

通过自定义多边形路径精准控制波浪起伏:

<div class="bg-[radial-gradient(ellipse_at_center,_var(--tw-gradient-stops))] from-blue-400 via-purple-500 to-pink-500 clip-path-[polygon(0_0,100%_0,100%_85%,95%_95%,90%_85%,85%_95%,80%_85%,75%_95%,70%_85%,65%_95%,60%_85%,55%_95%,50%_85%,45%_95%,40%_85%,35%_95%,30%_85%,25%_95%,20%_85%,15%_95%,10%_85%,5%_95%,0_85%)]">
  <div class="p-8 text-white">
    带径向渐变和波浪边框的容器
  </div>
</div>

修改clip-path中的坐标点,可自定义波浪的起伏幅度和数量。

三、完整可复用示例

将两者结合的完整代码:

<div class="relative overflow-hidden bg-[radial-gradient(ellipse_at_center,_var(--tw-gradient-stops))] from-blue-400 via-purple-500 to-pink-500">
  <div class="px-6 py-12 text-center text-white">
    <h2 class="text-2xl font-bold mb-4">径向渐变+波浪边框演示</h2>
    <p>完全匹配需求的Tailwind实现效果</p>
  </div>
  <div class="absolute bottom-0 left-0 w-full h-16">
    <div class="w-full h-full bg-white [mask-image:linear-gradient(to_top,rgba(0,0,0,1),rgba(0,0,0,0))]">
      <div class="absolute inset-0 bg-[radial-gradient(150px_150px_at_50%_0%,rgba(255,255,255,1)_48%,transparent_52%)]" style="background-size: 150px 100%"></div>
    </div>
  </div>
</div>

内容的提问来源于stack exchange,提问作者sabha mushtaq

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 14:57:28