html+css+js实现Badge 标记

实现效果:

代码实现:

html 复制代码
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Badge 标记</title>
  <link rel="stylesheet" href="./font_4689118_hfv5befzhmw/iconfont.css">
  <style>
    *{
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }
    ul{
      list-style: none;
    }
    .source{
      margin: 50px auto;
      width: 870px;
      height: 80px;
      padding: 24px;
      border: 1px solid #ecf5ff;
    }
    .content{
      display: flex;
    }
    .content .badge{
      margin-right: 40px;
      position: relative;
    }
    .badge button{
      cursor: pointer;
      width: 55px;
      height: 30px;
      color: #606266;
      border: 1px solid #c0c4cc;
      background-color: #fff;
      border-radius: 2px;
    }
    button:hover{
      border: 1px solid rgba(64, 158, 255, 0.1);
      background-color:rgba(64, 158, 255, 0.1);
      color:#409eff ;
    }
    .badge span{
      position: absolute;
      left: 45px;
      top: -10px;
      display: inline-block;
      width: 20px;
      height: 20px;
      line-height: 20px;
      border-radius: 50%;
      font-size: 12px;
      color: #fff;
      text-align: center;
      background-color: #f56c6c;
    }
    .badge:nth-child(1) span{
      width: 35px;
      border-radius: 10px;
    }
    .badge:nth-child(3) span{
      background-color: #409eff;
    }
    .badge:nth-child(4) span{
      background-color: #e6a23c;
    }
    .dropdown{
      position: relative;
    }
    .dropdown .header{
      cursor: pointer;
      height: 30px;
      line-height: 30px;
      font-size: 14px;
      color:#409eff ;
    }
    .footer{
      position: absolute;
      right: 0;
      padding: 12px 0;
      width: 100px;
      border: 1px solid #c0c4cc;
      border-radius: 3px;
      color: #606266;
      transition: all 0.3s ease;
      transform-origin: top;
    }
    .footer li{
      height: 38px;
      line-height: 38px;
      text-align: center;
    }
    .footer li:hover{
      cursor: pointer;
      background-color:rgba(64, 158, 255, 0.1);
      color:#409eff ;
    }
    .footer li span{
      display: inline-block;
      width: 18px;
      height: 18px;
      line-height: 18px;
      border-radius: 50%;
      font-size: 12px;
      color: #fff;
      text-align: center;
      background-color: #f56c6c;
      margin-left: 5px;
    }
    .footer li:nth-child(1) span{
      width:25px;
      border-radius: 9px;
    }
    
    .footer.hide{
      transform: scaleY(0); /* Hide the footer */
    }
  </style>
</head>
<body>
  <div class="source">
    <div class="content">
      <div class="badge">
        <button>评论</button>
        <span>12</span>
      </div>
      <div class="badge">
        <button>回复</button>
        <span>3</span>
      </div>
      <div class="badge">
        <button>评论</button>
        <span>1</span>
      </div>
      <div class="badge">
        <button>回复</button>
        <span>2</span>
      </div>
      <div class="dropdown">
        <div class="header">
          <span>点我查看</span>
          <span class="iconfont icon-jiantou"></span>
        </div>
        <ul class="footer hide">
          <li>评论<span>12</span></li>
          <li>回复<span>3</span></li>
        </ul>
      </div>
    </div>
  </div>
  <script>
    document.querySelector('.dropdown .header').addEventListener('click',function(){
      const footer = this.nextElementSibling;
      footer.classList.toggle('hide')
    })
  </script>
</body>
</html>
相关推荐
程序员爱技术2 分钟前
Vue 2 + JavaScript + vue-count-to 集成案例
前端·javascript·vue.js
并不会1 小时前
常见 CSS 选择器用法
前端·css·学习·html·前端开发·css选择器
悦涵仙子1 小时前
CSS中的变量应用——:root,Sass变量,JavaScript中使用Sass变量
javascript·css·sass
衣乌安、1 小时前
【CSS】居中样式
前端·css·css3
兔老大的胡萝卜1 小时前
ppk谈JavaScript,悟透JavaScript,精通CSS高级Web,JavaScript DOM编程艺术,高性能JavaScript pdf
前端·javascript
低代码布道师1 小时前
CSS的三个重点
前端·css
cs_dn_Jie5 小时前
钉钉 H5 微应用 手机端调试
前端·javascript·vue.js·vue·钉钉
开心工作室_kaic5 小时前
ssm068海鲜自助餐厅系统+vue(论文+源码)_kaic
前端·javascript·vue.js
有梦想的刺儿5 小时前
webWorker基本用法
前端·javascript·vue.js
清灵xmf6 小时前
TypeScript 类型进阶指南
javascript·typescript·泛型·t·infer