Skip to content

Timeline 时间轴

用于时间轴展示

CSS样式

全部 timeline 样式代码:

查看代码
css
/* HnuiIcon */
@import url('./icon.css');

/* 全局css变量 */

:root {
  /* #region vars-BrandColor */

  /* 品牌色 */
  --hnui-brand-color: #1f78ff;
  --hnui-brand-color1: #005ce5;
  --hnui-brand-color2: #4b83f7;
  --hnui-brand-color3: #3384ff;
  --hnui-brand-color4: #599bff;
  --hnui-brand-color5: #80b2ff;
  --hnui-brand-color6: #b2d1ff;
  --hnui-brand-color7: #cce0ff;
  --hnui-brand-color8: #d9e8ff;
  --hnui-brand-color9: #ebf3ff;
  --hnui-brand-color10: #f2f7ff;

  /* 状态颜色 */
  --hnui-brand-color-normal: var(--hnui-brand-color);
  --hnui-brand-color-hover: var(--hnui-brand-color3);
  --hnui-brand-color-active: var(--hnui-brand-color1);
  --hnui-brand-color-elected: var(--hnui-brand-color9);
  --hnui-brand-color-disabled: var(--hnui-brand-color7);

  --hnui-brand-color-disabled-border: var(--hnui-brand-color6);
  --hnui-brand-color-disabled-bg: var(--hnui-brand-color10);

  /* #endregion vars-BrandColor */

  /* #region vars-DomainColor */

  /* 功能色 */
  --hnui-success-color: #2ba471;
  --hnui-success-hover-color: #51bd90;
  --hnui-success-active-color: #2ba471;

  --hnui-warning-color: #faad14;
  --hnui-warning-hover-color: #ffc146;
  --hnui-warning-active-color: #db960b;

  --hnui-danger-color: #ff4d4d;
  --hnui-danger-hover-color: #ff7676;
  --hnui-danger-active-color: #d82a2a;

  --hnui-info-color: #8d97a6;
  --hnui-info-hover-color: #b2b7c0;
  --hnui-info-active-color: #707a89;

  /* #endregion vars-DomainColor */

  /* #region vars-NeutralColor */
  /* 中性色 */

  /* 标题文字 */
  --hnui-neutral-color-1: #2d2e33;

  /* 正文、重要信息文字、按钮文字、输入框正常状态文字等 */
  --hnui-neutral-color-2: #43454d;

  /* 内容文字、说明叙述文字 */
  --hnui-neutral-color-3: #5d606a;

  /* 提示性文字、辅助文本 */
  --hnui-neutral-color-4: #9298a0;

  /* 禁用文本 */
  --hnui-neutral-color-5: #b7bdc7;

  /* 描边格描边、输入文本描边、下拉选择描边等 */
  --hnui-neutral-color-6: #dfe2e7;

  /* 全局背景、禁用状态、分割线等 */
  --hnui-neutral-color-7: #f0f2f5;

  /* 最低颜色等 */
  --hnui-neutral-color-8: #fafbfc;

  /* #endregion vars-NeutralColor */

  /* 默认文字颜色 */
  --hnui-text-color: var(--hnui-neutral-color-2);

  --hnui-info-bg: #eceff4;
  --hnui-info-bg2: #e7e7e7;

  --hnui-color-white: #fff;
  --hnui-color-black: #000;

  --hnui-border-width: 1px;
  --hnui-border-dashed-width: 2px;
  --hnui-border-color: var(--hnui-neutral-color-6);

  --hnui-disabled-bg-color: var(--hnui-neutral-color-7);
  --hnui-disabled-color: var(--hnui-neutral-color-5);

  --hnui-control-height: 32px;
  --hnui-control-height-sm: 24px;
  --hnui-control-height-lg: 40px;

  --hnui-control-transparent: transparent;
}

.dark {
  --hnui-brand-color6: rgb(50, 59, 74);
  --hnui-brand-color7: #30353d;
  --hnui-brand-color8: #42484f;
  --hnui-brand-color9: #4c4f54;
  --hnui-brand-color10: #29292c;

  /* 中性色 */

  /* 标题文字 */
  --hnui-neutral-color-1: #c4c8dc;

  /* 正文、重要信息文字、按钮文字、输入框正常状态文字等 */
  --hnui-neutral-color-2: #b9bed3;

  /* 内容文字、说明叙述文字 */
  --hnui-neutral-color-3: #afb5c7;

  /* 提示性文字、辅助文本 */
  --hnui-neutral-color-4: #6a6f75;

  /* 禁用文本 */
  --hnui-neutral-color-5: #53565b;

  /* 描边格描边、输入文本描边、下拉选择描边等 */
  --hnui-neutral-color-6: #59595a;

  /* 全局背景、禁用状态、分割线等 */
  --hnui-neutral-color-7: #343535;

  /* 最低颜色等 */
  --hnui-neutral-color-8: #151516;

  --hnui-info-bg: #393b3d;

  --hnui-color-white: #000;
  --hnui-color-black: #fff;

  --hnui-control-transparent: transparent;
}

*,
::before,
::after {
  box-sizing: border-box;
}

body {
  color: var(--hnui-neutral-color-2);
}

/* #region vars-FontFamily */
@font-face {
  font-family: 'DIN';
  src: url('/fonts/D-DIN-PRO/D-DIN-PRO.woff2') format('woff2'),
    url('/fonts/D-DIN-PRO/D-DIN-PRO.woff') format('woff'),
    url('/fonts/D-DIN-PRO/D-DIN-PRO.ttf') format('truetype'),
    url('/fonts/D-DIN-PRO/D-DIN-PRO.eot') format('embedded-opentype'),
    url('/fonts/D-DIN-PRO/D-DIN-PRO.svg') format('svg');
  font-weight: normal;
  font-style: normal;
}

/* 使用数字字体 */
.use-font {
  font-family: DIN;
}
/* #endregion vars-FontFamily */

/* #region vars-BoxShadow */
/* 一级投影(默认向下) */
.hnui-box-shadow {
  box-shadow: 0px 6px 16px 6px rgba(0, 0, 0, 0.18);
}
.hnui-box-shadow.hover,
.hnui-box-shadow:hover {
  box-shadow: 0px 6px 16px 6px rgba(31, 120, 255, 0.18);
}

/* 二级投影(默认向下) */
.hnui-box-shadow_l2 {
  box-shadow: 0px 6px 16px 6px rgba(0, 0, 0, 0.12);
}
.hnui-box-shadow_l2.hover,
.hnui-box-shadow_l2:hover {
  box-shadow: 0px 6px 16px 6px rgba(31, 120, 255, 0.12);
}

/* 三级投影(默认向下) */
.hnui-box-shadow_l3 {
  box-shadow: 0px 6px 16px 6px rgba(0, 0, 0, 0.06);
}
.hnui-box-shadow_l3.hover,
.hnui-box-shadow_l3:hover {
  box-shadow: 0px 6px 16px 6px rgba(31, 120, 255, 0.06);
}
/* #endregion vars-BoxShadow */
css

/* ========== Timeline 时间轴基础样式 ========== */

.hnui-timeline {
  --hnui-timeline-dot-size: 10px;
  --hnui-timeline-dot-border-width: 2px;
  --hnui-timeline-line-width: 1px;
  --hnui-timeline-spacing: 24px;
  --hnui-timeline-dot-color: var(--hnui-brand-color);
  --hnui-timeline-line-color: var(--hnui-border-color);

  list-style: none;
  margin: 0;
  padding: 0;
}

/* ========== 垂直时间轴 ========== */

.hnui-timeline-item {
  margin-top: 0;
  position: relative;
  padding-bottom: var(--hnui-timeline-spacing);
  padding-left: 24px;
  min-width: 200px;
}

.hnui-timeline-item:last-child {
  padding-bottom: 0;
}

/* 时间轴线 */
.hnui-timeline-item::before {
  content: '';
  position: absolute;
  left: 4px;
  top: calc(var(--hnui-timeline-dot-size) + 8px);
  bottom: 0;
  width: var(--hnui-timeline-line-width);
  background-color: var(--hnui-timeline-line-color);
}

.hnui-timeline-item:last-child::before {
  display: none;
}

/* 时间轴节点 */
.hnui-timeline-item-dot {
  position: absolute;
  left: 0;
  top: 4px;
  width: var(--hnui-timeline-dot-size);
  height: var(--hnui-timeline-dot-size);
  border-radius: 50%;
  border: var(--hnui-timeline-dot-border-width) solid var(--hnui-timeline-dot-color);
  background-color: var(--hnui-color-white);
  z-index: 1;
}

/* 自定义节点图标 */
.hnui-timeline-item-dot-custom {
  position: absolute;
  left: -3px;
  top: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  color: var(--hnui-timeline-dot-color);
  background-color: var(--hnui-color-white);
  border-radius: 50%;
  z-index: 1;
}

.hnui-timeline-item-dot-custom .hnui-icon {
  font-size: 16px;
}

/* 时间轴内容 */
.hnui-timeline-item-content {
  position: relative;
  top: -2px;
}

.hnui-timeline-item-title {
  margin: 0 0 4px 0;
  font-size: 14px;
  line-height: 22px;
  color: var(--hnui-neutral-color-2);
  font-weight: normal;
}

.hnui-timeline-item-time {
  margin: 0;
  font-size: 14px;
  line-height: 22px;
  color: var(--hnui-neutral-color-4);
}

/* ========== 主题色变体 ========== */

/* 品牌色(默认) */
.hnui-timeline-item-primary .hnui-timeline-item-dot {
  border-color: var(--hnui-brand-color);
}

.hnui-timeline-item-primary .hnui-timeline-item-dot-custom {
  color: var(--hnui-brand-color);
}

/* 成功色 */
.hnui-timeline-item-success .hnui-timeline-item-dot {
  border-color: var(--hnui-success-color);
}

.hnui-timeline-item-success .hnui-timeline-item-dot-custom {
  color: var(--hnui-success-color);
}

/* 警告色 */
.hnui-timeline-item-warning .hnui-timeline-item-dot {
  border-color: var(--hnui-warning-color);
}

.hnui-timeline-item-warning .hnui-timeline-item-dot-custom {
  color: var(--hnui-warning-color);
}

/* 危险色 */
.hnui-timeline-item-danger .hnui-timeline-item-dot {
  border-color: var(--hnui-danger-color);
}

.hnui-timeline-item-danger .hnui-timeline-item-dot-custom {
  color: var(--hnui-danger-color);
}

/* 信息色 */
.hnui-timeline-item-info .hnui-timeline-item-dot {
  border-color: var(--hnui-info-color);
}

.hnui-timeline-item-info .hnui-timeline-item-dot-custom {
  color: var(--hnui-info-color);
}

/* ========== 水平时间轴 ========== */

.hnui-timeline-horizontal {
  display: flex;
  padding: 0;
}

.hnui-timeline-horizontal .hnui-timeline-item {
  flex: 1;
  padding-left: 0;
  padding-bottom: 0;
  padding-top: 32px;
  position: relative;
}

.hnui-timeline-horizontal .hnui-timeline-item::before {
  left: 0;
  right: 0;
  top: 4px;
  bottom: auto;
  width: auto;
  height: var(--hnui-timeline-line-width);
}

.hnui-timeline-horizontal .hnui-timeline-item:last-child::before {
  display: none;
}

.hnui-timeline-horizontal .hnui-timeline-item-dot {
  left: 0;
  top: 0;
}

.hnui-timeline-horizontal .hnui-timeline-item-dot-custom {
  left: -3px;
  top: -3px;
}

.hnui-timeline-horizontal .hnui-timeline-item-content {
  top: 0;
}

.hnui-timeline-horizontal .hnui-timeline-item-title {
  margin-bottom: 2px;
}

/* ========== 交替对齐(水平) ========== */

.hnui-timeline-horizontal-alternate {
  margin-top: 88px;
}

.hnui-timeline-horizontal-alternate .hnui-timeline-item:nth-child(odd) {
  padding-top: 0;
  padding-bottom: 32px;
}

.hnui-timeline-horizontal-alternate .hnui-timeline-item:nth-child(odd) .hnui-timeline-item-content {
  transform: translateY(calc(-100% - 22px));
}

.hnui-timeline-horizontal-alternate .hnui-timeline-item:nth-child(even) {
  padding-top: 32px;
  padding-bottom: 0;
}

/* ========== 倒序排列 ========== */

.hnui-timeline-reverse {
  display: flex;
  flex-direction: column-reverse;
}

.hnui-timeline-reverse .hnui-timeline-item:last-child {
  padding-bottom: var(--hnui-timeline-spacing);
}

.hnui-timeline-reverse .hnui-timeline-item:last-child::before {
  display: block;
}

.hnui-timeline-reverse .hnui-timeline-item:first-child {
  padding-bottom: 0;
}

.hnui-timeline-reverse .hnui-timeline-item:first-child::before {
  display: none;
}

/* === 暗色模式适配 === */
.dark .hnui-timeline-item-dot {
  background-color: var(--hnui-neutral-color-8);
}

.dark .hnui-timeline-item-dot-custom {
  background-color: var(--hnui-neutral-color-8);
}

.dark .hnui-timeline-item::before {
  background-color: var(--hnui-neutral-color-6);
}

.dark .hnui-timeline-item-title {
  color: var(--hnui-neutral-color-2);
}

.dark .hnui-timeline-item-time {
  color: var(--hnui-neutral-color-4);
}

基础用法

垂直方向的时间轴支持正序和倒序两种排列方式。

正序排列的时间轴
  • 事件一
    2022-01-01
  • 事件二
    2022-02-01
  • 事件三
    2022-03-01
  • 事件四
    2022-04-01
倒序排列的时间轴
  • 事件一
    2022-01-01
  • 事件二
    2022-02-01
  • 事件三
    2022-03-01
  • 事件四
    2022-04-01
查看代码
html
<ul class="hnui-timeline">
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件一</div>
      <div class="hnui-timeline-item-time">2022-01-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件二</div>
      <div class="hnui-timeline-item-time">2022-02-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件三</div>
      <div class="hnui-timeline-item-time">2022-03-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件四</div>
      <div class="hnui-timeline-item-time">2022-04-01</div>
    </div>
  </li>
</ul>
html
<ul class="hnui-timeline hnui-timeline-reverse">
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件一</div>
      <div class="hnui-timeline-item-time">2022-01-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件二</div>
      <div class="hnui-timeline-item-time">2022-02-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件三</div>
      <div class="hnui-timeline-item-time">2022-03-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件四</div>
      <div class="hnui-timeline-item-time">2022-04-01</div>
    </div>
  </li>
</ul>

自定义节点

可以通过自定义图标来个性化时间轴节点。

  • 事件一
    2022-01-01
  • 事件二
    2022-02-01
  • 事件三
    2022-03-01
  • 事件四
    2022-04-01
查看代码
html
<ul class="hnui-timeline">
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot-custom">
      <i class="hnui-icon-warn"></i>
    </div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件一</div>
      <div class="hnui-timeline-item-time">2022-01-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot-custom">
      <i class="hnui-icon-warn"></i>
    </div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件二</div>
      <div class="hnui-timeline-item-time">2022-02-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot-custom">
      <i class="hnui-icon-warn"></i>
    </div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件三</div>
      <div class="hnui-timeline-item-time">2022-03-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot-custom">
      <i class="hnui-icon-warn"></i>
    </div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件四</div>
      <div class="hnui-timeline-item-time">2022-04-01</div>
    </div>
  </li>
</ul>

不同主题节点

支持通过主题类名设置不同颜色的时间轴节点,包括品牌色、成功、警告、危险、信息等。

  • 已完成的时间
    2022-01-01
  • 成功的时间
    2022-02-01
  • 危险时间
    2022-03-01
  • 告警时间
    2022-04-01
  • 默认的时间
    2022-05-01
查看代码
html
<ul class="hnui-timeline">
  <li class="hnui-timeline-item hnui-timeline-item-primary">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">已完成的时间</div>
      <div class="hnui-timeline-item-time">2022-01-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item hnui-timeline-item-success">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">成功的时间</div>
      <div class="hnui-timeline-item-time">2022-02-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item hnui-timeline-item-danger">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">危险时间</div>
      <div class="hnui-timeline-item-time">2022-03-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item hnui-timeline-item-warning">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">告警时间</div>
      <div class="hnui-timeline-item-time">2022-04-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item hnui-timeline-item-info">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">默认的时间</div>
      <div class="hnui-timeline-item-time">2022-05-01</div>
    </div>
  </li>
</ul>

水平方向的时间轴

时间轴可以水平方向展示。

  • 事件一
    2022-01-01
  • 事件二
    2022-02-01
  • 事件三
    2022-03-01
  • 事件四
    2022-04-01
查看代码
html
<ul class="hnui-timeline hnui-timeline-horizontal">
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件一</div>
      <div class="hnui-timeline-item-time">2022-01-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件二</div>
      <div class="hnui-timeline-item-time">2022-02-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件三</div>
      <div class="hnui-timeline-item-time">2022-03-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件四</div>
      <div class="hnui-timeline-item-time">2022-04-01</div>
    </div>
  </li>
</ul>

不同内容的对齐方式

水平时间轴支持内容交替显示在时间轴上方和下方。

  • 事件一
    2022-01-01
  • 事件二
    2022-02-01
  • 事件三
    2022-03-01
  • 事件四
    2022-04-01
查看代码
html
<ul class="hnui-timeline hnui-timeline-horizontal hnui-timeline-horizontal-alternate">
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件一</div>
      <div class="hnui-timeline-item-time">2022-01-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件二</div>
      <div class="hnui-timeline-item-time">2022-02-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件三</div>
      <div class="hnui-timeline-item-time">2022-03-01</div>
    </div>
  </li>
  <li class="hnui-timeline-item">
    <div class="hnui-timeline-item-dot"></div>
    <div class="hnui-timeline-item-content">
      <div class="hnui-timeline-item-title">事件四</div>
      <div class="hnui-timeline-item-time">2022-04-01</div>
    </div>
  </li>
</ul>

统一UI