css 遮盖滚动条,鼠标移上显示

html 复制代码
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      /* pc端,遮盖x滚动条 */
      @media (min-width: 768px) {
        .overflow-x-scroll {
          overflow-x: auto;
        }

        .cover-scrollbar-x:has(.overflow-x-scroll) {
          position: relative;
          overflow-x: hidden;
          background-color: white;
        }

        .cover-scrollbar-x > .overflow-x-scroll {
          padding-bottom: 20px;
        }

        /* 遮盖x滚动条 */
        .cover-scrollbar-x:has(.overflow-x-scroll)::after {
          content: '';
          display: block;
          z-index: 1;
          position: absolute;
          width: 100%;
          height: 20px;
          bottom: 0;
          background-color: inherit;
        }

        .cover-scrollbar-x:has(.overflow-x-scroll):hover::after {
          display: none;
        }
      }
    </style>
  </head>
  <body>
    <div class="cover-scrollbar-x">
      <div class="overflow-x-scroll">
        <p style="width: 3000px;">
          css使用 ::after + position: absolute 遮盖滚动条,css使用 ::after + position: absolute 遮盖滚动条,css使用 ::after + position: absolute 遮盖滚动条,css使用 ::after + position: absolute
          遮盖滚动条,css使用 ::after + position: absolute 遮盖滚动条,css使用 ::after + position: absolute 遮盖滚动条,css使用 ::after + position: absolute 遮盖滚动条
        </p>
      </div>
    </div>
  </body>
</html>

需要丰富的效果,可以用 javascript 库 simplebar

相关推荐
小蜗 strong5 分钟前
和电脑猜拳(随机程序应用)
服务器·前端·python
下家1 小时前
为了脱离前端鄙视链,于是自己写个框架 - React 党看完沉默了
前端·前端框架
zhiyouTech2 小时前
从“被看见“到“被信任“:关于信源评级机制的一点观察
大数据·前端·人工智能
Hashan2 小时前
Vibe Coding 下前后端怎么对接接口?后端不给力的兜底方案
前端·后端·vibecoding
你挚爱的强哥2 小时前
【sgKeyboard】自定义组件:虚拟键盘
前端·javascript·计算机外设
锅里游的鱼吖2 小时前
echarts自定义折线图
前端·javascript·数据库
hunteritself3 小时前
卷卷卷!GPT-6 Sol、Luna 正式发布,OpenAI 开始卷价格了
大数据·前端·人工智能·深度学习·transformer
何何____3 小时前
Vue 全局事件总线详解
前端·javascript·vue.js
涉密IT资质笔记4 小时前
涉密人员脱密期管理规范:期限分级模型、就业限制边界与违规认定标准
java·服务器·前端·网络·数据库
u0111026754 小时前
工具页案例图如何编写 alt让图片说明与处理场景对应
java·前端·javascript·图像处理·人工智能·算法·ai作画