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>
相关推荐
10年前端老司机2 小时前
什么!纯前端也能识别图片中的文案、还支持100多个国家的语言
前端·javascript·vue.js
magic 2453 小时前
模拟 AJAX 提交 form 表单及请求头设置详解
前端·javascript·ajax
只喜欢赚钱的棉花没有糖8 小时前
http的缓存问题
前端·javascript·http
蓝婷儿8 小时前
Python 爬虫入门 Day 2 - HTML解析入门(使用 BeautifulSoup)
爬虫·python·html
让梦想疯狂8 小时前
开源、免费、美观的 Vue 后台管理系统模板
前端·javascript·vue.js
葡萄糖o_o9 小时前
ResizeObserver的错误
前端·javascript·html
MK-mm9 小时前
CSS盒子 flex弹性布局
前端·css·html
sunbyte9 小时前
50天50个小项目 (Vue3 + Tailwindcss V4) ✨ | AnimatedNavigation(动态导航)
前端·javascript·vue.js·tailwindcss
JustHappy10 小时前
啥是Hooks?为啥要用Hooks?Hooks该怎么用?像是Vue中的什么?React Hooks的使用姿势(下)
前端·javascript·react.js
江城开朗的豌豆11 小时前
Vue中Token存储那点事儿:从localStorage到内存的避坑指南
前端·javascript·vue.js