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

如何删除CSS实现的时间轴第一个子项顶部与最后一个子项底部的边框线

解决方案

不需要额外新增绝对定位元素覆盖,仅通过调整现有CSS规则即可实现需求,修改逻辑如下:
原有方案中竖线是每个li的左边框,会天然贯穿整个li高度,因此首尾会出现多余线条。我们改为给外层ul绘制统一竖线,利用圆点的白色背景天然遮盖首尾溢出的部分即可,仅需少量规则调整,原有其他代码无需大改。

修改后完整可运行的CSS代码如下:

body {
  margin: 0;
}
.tree {
  position: relative;
  list-style: none;
  padding-left: 0;
}
/* 新增:外层ul绘制统一贯穿竖线 */
.tree::before {
  content: '';
  position: absolute;
  left: 10px;
  top: 0;
  height: 100%;
  width: 1px;
  background: #abaaed;
}
li {
  padding-bottom: 50px;
  position: relative;
  padding-left: 20px;
  margin-left: 10px;
  height: auto;
  display: flex;
  align-items: center;
}
li:last-child {
  padding-bottom: 0;
}
li::before {
    content: '';
    width: 15px;
    height: 15px;
    background: white;
    border: 1px solid #4e5ed3;
    border-radius: 50%;
    position: absolute;
    left: -8px;
    /* 非首尾节点圆点垂直居中 */
    top: 50%;
    transform: translateY(-50%);
}
li::after {
    content: '';
    width: 10px;
    height: 2px;
    position: absolute;
    left: 7px;
    top: 50%;
    transform: translateY(-50%);
    background: #4e5ed3;
}
/* 首节点圆点定位到顶部,遮盖竖线上端多余部分 */
li:first-child::before {
  top: 0;
  transform: none;
}
/* 尾节点圆点定位到底部,遮盖竖线下端多余部分 */
li:last-child::before {
  bottom: 0;
  top: auto;
  transform: none;
}
button {
  padding: 10px 20px;
}

修改后即可清除首尾多余的竖线,同时时间轴中间的连接线条保持完整。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.10.19 13:15:01