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>
相关推荐
LuciferHuang3 小时前
震惊!三万star开源项目竟有致命Bug?
前端·javascript·debug
GISer_Jing3 小时前
前端实习总结——案例与大纲
前端·javascript
姑苏洛言4 小时前
编写产品需求文档:黄历日历小程序
前端·javascript·后端
知识分享小能手4 小时前
Vue3 学习教程,从入门到精通,使用 VSCode 开发 Vue3 的详细指南(3)
前端·javascript·vue.js·学习·前端框架·vue·vue3
姑苏洛言4 小时前
搭建一款结合传统黄历功能的日历小程序
前端·javascript·后端
hackchen5 小时前
Go与JS无缝协作:Goja引擎实战之错误处理最佳实践
开发语言·javascript·golang
你的人类朋友6 小时前
🤔什么时候用BFF架构?
前端·javascript·后端
知识分享小能手6 小时前
Bootstrap 5学习教程,从入门到精通,Bootstrap 5 表单验证语法知识点及案例代码(34)
前端·javascript·学习·typescript·bootstrap·html·css3
我命由我123457 小时前
前端开发问题:SyntaxError: “undefined“ is not valid JSON
开发语言·前端·javascript·vue.js·json·ecmascript·js