我给你最简洁、直接能用的 CSS3 实现代码:纯 CSS 画三角形 + 椭圆渐变,两种效果都能直接复制到 Next.js + Tailwind 里使用。
不用图片,纯边框实现,最标准写法。
css
.triangle-up {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-bottom: 100px solid #ff4757;
}css
.triangle-down {
width: 0;
height: 0;
border-left: 50px solid transparent;
border-right: 50px solid transparent;
border-top: 100px solid #2ed573;
}css
.triangle-left {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
border-right: 100px solid #1e90ff;
}css
.triangle-right {
width: 0;
height: 0;
border-top: 50px solid transparent;
border-bottom: 50px solid transparent;
border-left: 100px solid #ffa502;
}css
.ellipse {
width: 200px;
height: 100px;
border-radius: 50%;
}原理:宽高不一致 +
border-radius:50%= 椭圆
css
.ellipse-linear {
width: 200px;
height: 100px;
border-radius: 50%;
background: linear-gradient(45deg, #ff9a9e, #fad0c4, #fad0c4);
}css
.ellipse-radial {
width: 200px;
height: 100px;
border-radius: 50%;
background: radial-gradient(circle, #a8edea 0%, #fed6e3 100%);
}如果你项目里有 Tailwind CSS,不用写 CSS,直接用类名:
jsx
<div className="w-0 h-0 border-l-[20px] border-r-[20px] border-b-[40px] border-l-transparent border-r-transparent border-b-red-500" />jsx
<div className="w-[200px] h-[100px] rounded-full bg-gradient-to-r from-pink-300 via-purple-300 to-blue-300" />border + transparent 实现width≠height + border-radius:50%linear-gradient / radial-gradient原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。
原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。