Skip to content

Badge 徽标

CSS样式

全部 badge 样式代码:

查看代码
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
@import url('../button/button.css');

/* ============================================
   徽标容器
   ============================================ */
.hnui-badge {
  position: relative;
  display: inline-block;
}
.hnui-icon {
  font-size: 16px;
}

/* ============================================
   徽标基础样式
   ============================================ */
.hnui-badge-count {
  position: absolute;
  top: 0;
  right: 0;
  transform: translate(50%, -50%);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 18px;
  height: 18px;
  padding: 0 6px;
  background-color: var(--hnui-danger-color);
  color: var(--hnui-color-white);
  font-size: 12px;
  line-height: 1;
  border-radius: 9px;
  white-space: nowrap;
  font-family: var(--hnui-font-family);
  box-sizing: border-box;
}

/* ============================================
   红点样式
   ============================================ */
.hnui-badge-dot {
  position: absolute;
  top: 0;
  right: 0;
  transform: translate(50%, -50%);
  width: 8px;
  height: 8px;
  background-color: var(--hnui-danger-color);
  border-radius: 50%;
}

/* ============================================
   方形徽标
   ============================================ */
.hnui-badge-count.hnui-badge-square {
  border-radius: 3px;
}

/* ============================================
   小尺寸徽标
   ============================================ */
.hnui-badge-count.hnui-badge-small {
  min-width: 14px;
  height: 14px;
  padding: 0 4px;
  font-size: 10px;
  border-radius: 7px;
}

.hnui-badge-count.hnui-badge-small.hnui-badge-square {
  border-radius: 2px;
}

.hnui-badge-dot.hnui-badge-small {
  width: 6px;
  height: 6px;
}

/* ============================================
   徽标内容(用于包裹按钮、图标等)
   ============================================ */
.hnui-badge-content {
  display: inline-block;
}

/* ============================================
   演示辅助样式
   ============================================ */
.hnui-badge-demo-icon {
  font-size: 24px;
  color: var(--hnui-text-color);
}

/* ============================================
   暗色模式适配
   ============================================ */
.dark .hnui-badge-count {
  background-color: var(--hnui-danger-color);
  color: var(--hnui-color-white);
}

.dark .hnui-badge-dot {
  background-color: var(--hnui-danger-color);
}

.dark .hnui-badge-demo-icon {
  color: var(--hnui-neutral-color-2);
}

红点样式徽标数

解锁新徽章
查看代码
html
<div class="hnui-badge">
  <button class="hnui-btn">填充按钮</button>
  <span class="hnui-badge-dot"></span>
</div>
html
<div class="hnui-badge">
  <button class="hnui-btn hnui-btn-icon">
    <i class="hnui-icon hnui-icon-mail"></i>
  </button>
  <span class="hnui-badge-dot"></span>
</div>
html
<div class="hnui-badge">
  <span>解锁新徽章</span>
  <span class="hnui-badge-dot"></span>
</div>
html
<div class="hnui-badge">
  <IconUser class="hnui-icon"></IconUser>
  <span class="hnui-badge-dot"></span>
</div>

红点样式徽标数

2
99
99+
查看代码
html
<div class="hnui-badge">
  <button class="hnui-btn">填充按钮</button>
  <span class="hnui-badge-count">2</span>
</div>
html
<div class="hnui-badge">
  <button class="hnui-btn hnui-btn-icon">
    <i class="hnui-icon hnui-icon-mail"></i>
  </button>
  <span class="hnui-badge-count">99</span>
</div>
html
<div class="hnui-badge">
  <button class="hnui-btn hnui-btn-icon">
    <i class="hnui-icon hnui-icon-mail"></i>
  </button>
  <span class="hnui-badge-count">99+</span>
</div>

自定义徽标

NEW
查看代码
html
<div class="hnui-badge">
  <button class="hnui-btn">填充按钮</button>
  <span class="hnui-badge-count">NEW</span>
</div>

徽标样式

圆形
2
方形
2
查看代码
html
<div class="hnui-badge">
  <button class="hnui-btn">填充按钮</button>
  <span class="hnui-badge-count">2</span>
</div>
html
<div class="hnui-badge">
  <button class="hnui-btn">填充按钮</button>
  <span class="hnui-badge-count hnui-badge-square">2</span>
</div>

徽标大小

中尺寸(默认)
2
2
小尺寸
2
2
查看代码
html
<div class="hnui-badge">
  <button class="hnui-btn">填充按钮</button>
  <span class="hnui-badge-count">2</span>
</div>
html
<div class="hnui-badge">
  <button class="hnui-btn">填充按钮</button>
  <span class="hnui-badge-count hnui-badge-square">2</span>
</div>
html
<div class="hnui-badge">
  <button class="hnui-btn hnui-btn-sm">填充按钮</button>
  <span class="hnui-badge-count hnui-badge-small">2</span>
</div>
html
<div class="hnui-badge">
  <button class="hnui-btn hnui-btn-sm">填充按钮</button>
  <span class="hnui-badge-count hnui-badge-small hnui-badge-square">2</span>
</div>

统一UI