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

如何在Dart Flutter中实现容器内凹曲线效果?

实现内凹曲线底部导航栏的几种方案

以下是几种实现图中内凹曲线底部导航栏的实用方案:

1. CSS clip-path 裁剪方案

通过clip-path的polygon属性直接定义导航栏的形状,适合简单内凹场景:

<!-- HTML结构 -->
<div class="bottom-nav">
  <div class="nav-item">首页</div>
  <div class="nav-item">发现</div>
  <div class="nav-item">我的</div>
</div>
/* CSS样式 */
.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #fff;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  /* 定义内凹多边形,调整数值可控制内凹位置和深度 */
  clip-path: polygon(0 0, 40% 0, 45% 20%, 55% 20%, 60% 0, 100% 0, 100% 100%, 0 100%);
  display: flex;
  justify-content: space-around;
  align-items: center;
}

.nav-item {
  font-size: 14px;
  color: #666;
}

2. 伪元素 + border-radius 模拟方案

通过在导航栏顶部添加与页面背景色一致的圆形伪元素,营造柔和内凹效果:

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #fff;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-top: 10px;
}

.bottom-nav::before {
  content: "";
  position: absolute;
  top: -10px;
  left: 50%;
  transform: translateX(-50%);
  width: 60px;
  height: 20px;
  background: #f5f5f5; /* 与页面主体背景色保持一致 */
  border-bottom-left-radius: 30px;
  border-bottom-right-radius: 30px;
}

3. SVG 背景方案

如果需要自定义复杂曲线,SVG是最优选择,将SVG作为导航栏顶部背景:

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  height: 60px;
  background: #fff;
  /* 内嵌SVG作为顶部背景,修改path可自定义曲线形状 */
  background-image: url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 20"><path d="M0,0 L40,0 Q45,10 55,10 Q60,0 100,0 L100,20 L0,20 Z" fill="%23fff"/></svg>');
  background-repeat: no-repeat;
  background-size: 100% 20px;
  background-position: top center;
  box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
  display: flex;
  justify-content: space-around;
  align-items: center;
  padding-top: 20px;
}

内容的提问来源于stack exchange,提问作者Azmat Ullah

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.09 00:10:21