You need to enable JavaScript to run this app. 如何使用HTML和CSS在圆角曲线框内添加竖线分隔及顶部曲边图例
优惠活动
大模型
产品
解决方案
定价
更多

如何使用HTML和CSS在圆角曲线框内添加竖线分隔及顶部曲边图例

基于原有代码的完整实现

核心难点实现逻辑

  • 上下预留空隙的竖分隔线:不依赖区块边框实现,单独创建1px宽的定位元素作为分隔线,通过设置分隔线的实际高度、垂直居中定位,自然在上下留出空白,调整空隙大小只需要修改高度值即可,调试门槛低
  • 顶部带曲线边框的图例:用CSS伪元素制作图例左右两侧的内凹弧形,不需要切图、不需要额外嵌套元素,纯代码就能实现跨在容器上边缘的曲线衔接效果

可直接运行的完整代码

<!DOCTYPE html>
<html>
<head>
<style>
/* 保留原有容器基础样式,补充相对定位属性供内部元素定位 */
#rcorners2 {
  position: relative;
  border-radius: 25px;
  border: 2px solid #73AD21;
  padding: 20px; 
  width: 650px;
  height: 150px;  
  /* 用flex布局实现三区块等宽排列,维护简单 */
  display: flex;
  justify-content: space-between;
}

/* 竖分隔线基础样式 */
.divider {
  position: absolute;
  width: 1px;
  background-color: #73AD21;
  /* 设置分隔线实际高度,上下自然留出空隙 */
  height: 80px;
  top: 50%;
  transform: translateY(-50%);
}
/* 两个分隔线的横向位置,将容器横向三等分 */
.divider-left {
  left: calc(100% / 3);
}
.divider-right {
  left: calc(100% * 2 / 3);
}

/* 顶部图例基础样式 */
.container-legend {
  position: absolute;
  top: -18px;
  left: calc(100% / 3);
  width: calc(100% / 3);
  height: 36px;
  background-color: #e8f5e0;
  /* 图例顶部圆角 */
  border-radius: 12px 12px 0 0;
}
/* 伪元素做左右两侧的曲线衔接 */
.container-legend::before,
.container-legend::after {
  content: '';
  position: absolute;
  bottom: 0;
  width: 12px;
  height: 12px;
}
/* 左侧内凹曲线 */
.container-legend::before {
  left: -12px;
  background: transparent;
  border-bottom-right-radius: 12px;
  box-shadow: 6px 6px 0 0 #e8f5e0;
}
/* 右侧内凹曲线 */
.container-legend::after {
  right: -12px;
  background: transparent;
  border-bottom-left-radius: 12px;
  box-shadow: -6px 6px 0 0 #e8f5e0;
}

/* 三个内容区块的基础样式,预留内边距避免内容贴边 */
.section {
  width: 33.33%;
  padding: 0 10px;
}
</style>
</head>
<body>
<div id="rcorners2">
  <div class="container-legend">图例文本</div>
  <div class="divider divider-left"></div>
  <div class="divider divider-right"></div>
  <div class="section">第一区块内容</div>
  <div class="section">第二区块内容</div>
  <div class="section">第三区块内容</div>
</div>
</body>
</html>

调试提示:如果需要调整分隔线的上下空隙大小,直接修改.divider选择器里的height值即可;如果需要调整图例的弧形大小,修改伪元素的width、height和对应的border-radius、box-shadow值即可。


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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.11.04 14:06:09