Html设计小技巧之毛玻璃效果

本文详细介绍了如何通过CSS和HTML实现毛玻璃效果,包括代码示例和关键属性如backdrop-filter和BoxShadow的使用。
摘要由CSDN通过智能技术生成

Html设计小技巧之毛玻璃效果

        1. 效果展示

        2. 代码展示

        CSS代码:

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  /* 居中对齐 */
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  /* 线性渐变 */
  background: linear-gradient(lightblue 10%, lightskyblue 40%, DodgerBlue 70%);
}
/* 使用::before和::after效果不好 */
.main, .before, .after {
  background-color: rgba(255, 255, 255, 0.3);
  backdrop-filter: blur(30px);
  opacity: 0.5;
  /* 设置外阴影蓝色和内阴影白色 */
  box-shadow: 20px 20px 40px 5px DeepSkyBlue, inset 2px 2px 10px white;
}

.main {
  /* 文字居中对齐 */
  display: flex;
  justify-content: center;
  align-items: center;
  width: 500px;
  height: 500px;
  /* 添加外阴影:白色 */
  box-shadow: 20px 20px 40px 5px DeepSkyBlue, inset 2px 2px 10px white, 
  -10px -10px 30px white;
  z-index: 0;
}

.before {
  position: absolute;
  top: 60%;
  left: 60%;
  width: 250px;
  height: 250px;
  z-index: -1;
}

.after {
  position: absolute;
  bottom: 60%;
  right: 60%;
  width: 250px;
  height: 250px;
  z-index: 1;
}

a {
  color: white;
  font-size: 36px;
  z-index: 1;
  /* 取消下划线 */
  text-decoration: none;
}

        HTML代码:

<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Html小技巧之毛玻璃特效</title>
  <link rel="stylesheet" href="css/001.css">
</head>

<body>
  <div class="before"></div>
  <div class="main">
    <a href="#">Backdrop Filter</a>
  </div>
  <div class="after"></div>
</body>

</html>

  • 12
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值