CSS阴影&渐变

阴影:

  • x方向阴影的位移,y方向上阴影的位移, 阴影的模糊程度,阴影的颜色和其透明度,inset为内部
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .shadow1 {
        height: 100px;
        width: 100px;
        border: 1px solid #000;
        box-shadow: 10px 10px 10px #95215e;
      }

      .shadow2 {
        height: 100px;
        width: 100px;
        border: 1px solid #000;
        box-shadow: -10px -10px 10px #95215e;
      }

      .shadow3 {
        height: 100px;
        width: 100px;
        border: 1px solid #000;
        box-shadow: 0px -10px 10px #95215e inset;
      }

      .shadow4 {
        height: 100px;
        width: 100px;
        border: 1px solid #000;
        box-shadow: 0px 0px 10px #aaa;
      }
    </style>
  </head>
  <body>
    <div>阴影效果:</div>
    <div style="margin-top: 20px"></div>
    <div class="shadow1"></div>
    <div class="shadow2" style="margin-top: 40px"></div>
    <div class="shadow3" style="margin-top: 40px"></div>
    <div class="shadow4" style="margin-top: 40px"></div>
  </body>
</html>

  • 一个好看的阴影效果:
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        background-color: #000;
      }
      div {
        position: absolute;
        top: calc(50% - 150px);
        left: calc(50% - 150px);
        width: 300px;
        height: 300px;
        border-radius: 50%;
        box-shadow: inset 0 0 50px #fff, inset 20px 0 80px #f0f, inset -20px 0 80px #0ff, inset 20px 0 300px #f0f,
          inset -20px 0 300px #0ff, 0 0 50px #fff, -10px 0 80px #f0f, 10px 0 80px #0ff;
      }
    </style>
  </head>
  <body>
    <div></div>
  </body>
</html>

渐变:

  • 线性渐变(Linear Gradients)- 向下/向上/向左/向右/对角方向deg/颜色
  • 颜色支持rgba,设置透明,注意兼容性,还可以后面加百分比
  • 径向渐变(Radial Gradients)- 由它们的中心定义- circle/ellipse/颜色
<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .div1 {
        width: 100px;
        height: 50px;
        background: -webkit-linear-gradient(#00c7a6, red);
        background: -o-linear-gradient(#00c7a6, red);
        background: -moz-linear-gradient(#00c7a6, red);
        background-image: linear-gradient(-90deg, red, yellow, #ccc);
      }
      .div2 {
        width: 100px;
        height: 100px;
        background-image: radial-gradient(circle, red 10%, yellow, green);
        margin-top: 60px;
      }
    </style>
  </head>
  <body>
    <div class="div1"></div>
    <div class="div2"></div>
  </body>
</html>


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值