毛玻璃 has 选择器卡片悬停效果

效果展示

页面结构

从上述的效果展示可以看到,页面是由多个卡片组成,并且鼠标悬停在卡片上时,会旋转用户图片并且韩式对应的用户信息框。

CSS3 知识点

  • :has 属性的运用

实现页面整体结构

html 复制代码
<div class="container">
  <div class="card" data-color="clr1">
    <div class="img_box">
      <img src="images/user-1.jpg" />
    </div>
    <div class="glass">
      <h3>
        Someone
        <br />
        <span>SEO Expert</span>
      </h3>
      <ul>
        <li style="--i: 1">
          <a href="#">
            <i class="fa fa-qq" aria-hidden="true"></i>
          </a>
        </li>
        <li style="--i: 2">
          <a href="#">
            <i class="fa fa-weixin" aria-hidden="true"></i>
          </a>
        </li>
        <li style="--i: 3">
          <a href="#">
            <i class="fa fa-weibo" aria-hidden="true"></i>
          </a>
        </li>
        <li style="--i: 4">
          <a href="#">
            <i class="fa fa-tencent-weibo" aria-hidden="true"></i>
          </a>
        </li>
      </ul>
    </div>
  </div>
</div>

实现卡片基础样式

css 复制代码
.container .card {
  position: relative;
  width: 200px;
  height: 200px;
  border-radius: 10px;
  display: flex;
  justify-content: center;
  align-items: center;
  transition: 0.5s;
}

实现用户头像样式

css 复制代码
.container .card .img_box {
  position: absolute;
  inset: 0;
  border-radius: 12px;
  border: 4px solid rgba(0, 0, 0, 0.2);
}

.container .card .img_box img {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transition: 0.5s;
  border-radius: 10px;
}

.container .card:hover .img_box img {
  opacity: 0.5;
}

实现用户信息框样式

css 复制代码
.container .card .glass {
  position: absolute;
  inset: 0;
  background: linear-gradient(#fff2, transparent);
  border: 1px solid rgba(255, 255, 255, 0.1);
  box-shadow: 0 15px 15px rgba(0, 0, 0, 0.25);
  backdrop-filter: blur(15px);
  border-radius: 10px;
  scale: 0;
  display: flex;
  flex-flow: row wrap;
  justify-content: center;
  align-items: center;
  overflow: hidden;
  opacity: 0;
  transition: 0.5s;
}

.container .card .glass::before {
  content: "";
  display: block;
  position: absolute;
  bottom: 0;
  width: 100%;
  height: 50px;
  background: rgba(255, 255, 255, 0.05);
}

.container .card ul {
  position: absolute;
  bottom: 14px;
  width: 100%;
  display: flex;
  justify-content: center;
  gap: 15px;
}

.container .card ul li {
  list-style: none;
}

.container .card ul a {
  color: #fff8;
  font-size: 1.25em;
  scale: 0;
  transition: 0.25s;
  transition-delay: scale calc(0.2s * var(--i));
}

.container .card:hover ul a {
  scale: 1;
}

.container .card ul a:hover {
  color: #fff;
}

实现对应的悬停样式

css 复制代码
.container .card:hover .img_box img {
  opacity: 0.5;
}

.container .card:hover {
  transform: rotate(-15deg);
}

.container .card:hover .glass {
  scale: 1;
  opacity: 1;
  transform: rotate(20deg);
}

使用 has 属性修改背景颜色

css 复制代码
body:has(.card[data-color="clr1"]:hover) {
  background: #d18c55;
}

body:has(.card[data-color="clr2"]:hover) {
  background: #fff6a3;
}

body:has(.card[data-color="clr3"]:hover) {
  background: #eeb973;
}

body:has(.card[data-color="clr4"]:hover) {
  background: #f7f3ea;
}

完整代码下载

完整代码下载

相关推荐
徐同保1 分钟前
使用yarn@4.6.0装包,项目是react+vite搭建的,项目无法启动,报错:
前端·react.js·前端框架
Qrun1 小时前
Windows11安装nvm管理node多版本
前端·vscode·react.js·ajax·npm·html5
中国lanwp1 小时前
全局 npm config 与多环境配置
前端·npm·node.js
JELEE.2 小时前
Django登录注册完整代码(图片、邮箱验证、加密)
前端·javascript·后端·python·django·bootstrap·jquery
TeleostNaCl4 小时前
解决 Chrome 无法访问网页但无痕模式下可以访问该网页 的问题
前端·网络·chrome·windows·经验分享
charlie1145141914 小时前
CSS笔记4:CSS:列表、边框、表格、背景、鼠标与常用长度单位
css·笔记·学习·css3·教程
前端大卫5 小时前
为什么 React 中的 key 不能用索引?
前端
你的人类朋友5 小时前
【Node】手动归还主线程控制权:解决 Node.js 阻塞的一个思路
前端·后端·node.js
小李小李不讲道理7 小时前
「Ant Design 组件库探索」五:Tabs组件
前端·react.js·ant design
毕设十刻7 小时前
基于Vue的学分预警系统98k51(程序 + 源码 + 数据库 + 调试部署 + 开发环境配置),配套论文文档字数达万字以上,文末可获取,系统界面展示置于文末
前端·数据库·vue.js