【css3学习系列】之box-shadow,radial-gradient,linear-gradient

Talk is cheap.Show me the code.

1.box-shadow

clipboard.png

 <div class="chopsticks"></div>
 .chopsticks{
      position: absolute;
      left: 400px;
      top: 80px;
      width: 10px;
      height: 250px;
      background-color: #bb8855;
      border-radius: 3px;
      -webkit-border-radius: 3px;  
      box-shadow: 0 1px 2px 1px rgba(0, 0, 0, 0.2),inset 0 -5px 2px 0 rgba(0,0,0,0.1);
      z-index: 99;
  }
    .chopsticks:before{
        content: '';
        position: absolute;
        left: 20px;
        top: 0px;
        width: 10px;
        height: 250px;
        background-color: #bb8855;
        border-radius: 3px;
        -webkit-border-radius: 3px;
        box-shadow: 0 1px 2px 1px rgba(0, 0, 0, 0.2),inset 0 -5px 2px 0 rgba(0,0,0,0.1);
        z-index: 99;
    }

【注】:box-shadow是由逗号分隔的阴影列表,每个逗号隔开的便是一个阴影,每个阴影由 2-4 个长度值、可选的颜色值以及可选的 inset 关键词来规定,可给每个class添加一个或多个阴影。阴影的颜色是任意的,所以阴影有很多妙用。

2.border-radius

clipboard.png

 <div class="egg"></div>

.egg{
        position: absolute;
        top: 20px;
        left: 35px;
        width: 80px;
        height: 100px;
        z-index: 7;
        border-radius: 50% / 60% 60% 40% 40%;
        -webkit-border-radius:50% / 60% 60% 40% 40%;        
        background-color: #fff;
        transform:rotate(20deg);
    }
   .egg:before{
        content: '';
        position: absolute;
        top: 30%;
        left: 24%;
        width: 50%;
        height: 50%;
        z-index: 7;
        border-radius: 50%;
        -webkit-border-radius:50%;
        background: #FC0;
        box-shadow: 0 0 2px 2px #f90,inset 0 0 5px 1px rgba(255, 153, 0, 0.5);
        }

【注】:border-radius

  1. 一个值,border-radius:50px;表示水平半径和垂直半径相等;
    两个值:border-radius:100px / 50px;"/"前的值表示水平半径,"/"后的值表示垂直半径,两个值 的顺序与一个值的顺序相同:左上,右上,右下,左下。

  2. css3还提供了对每个角进行设置:

    • border-top-left-radius

    • border-top-right-radius

    • border-bottom-right-radius

    • border-bottom-left-radius

3.radial-gradient(径向渐变)

(demo可参考下面的图,碗和面条都是用径向渐变实现的)

 background-image:radial-gradient(ellipse at center center, rgba(0, 0, 0, 0) 20%, rgba(0, 0, 0, 0.1) 21%, #ffcc33 21%, #ffcc33 23%, rgba(0, 0, 0, 0.1) 23%, rgba(0, 0, 0, 0) 24%)
 background-image:-webkit-radial-gradient(center center,ellipse, rgba(0, 0, 0, 0) 20%, rgba(0, 0, 0, 0.1) 21%, #ffcc33 21%, #ffcc33 23%, rgba(0, 0, 0, 0.1) 23%, rgba(0, 0, 0, 0) 24%)

【要点】:

  1. radial-gradient(渐变形状 at 渐变圆心,渐变颜色 [颜色渐变开始位置(距离渐变圆心的大小)],渐变颜色[颜色渐变位置])

  2. -webkit-radial-gradient(渐变圆心,渐变形状,渐变颜色 [颜色渐变开始位置(距离渐变圆心的大小)],渐变颜色 [颜色渐变位置])

  3. 颜色渐变位置不写时,默认第一个颜色位置是0,第二个是100%。

  4. 不在指定渐变区域的,以距离其最近的颜色填充。

4.linear-gradient(线性渐变)

(demo可参考下面的图,海苔是用线性渐变实现的)

   background-image: linear-gradient(-20deg, rgba(0, 0, 0, 0.9) 50%, rgba(0, 34, 0, 0.95) 95%);
   background-image: -webkit-linear-gradient(110deg, rgba(0, 0, 0, 0.9) 50%, rgba(0, 34, 0, 0.95) 95%);

【要点】:可用方向或角度值指定渐变的方向(或角度)。
to left:设置渐变为从右到左。相当于: 270deg
to right:设置渐变从左到右。相当于: 90deg
to top:设置渐变从下到上。相当于: 0deg
to bottom:设置渐变从上到下。相当于: 180deg。这是默认值,等同于留空不写。

最后奉上一碗纯css拉面。

clipboard.png

【注】: 拉面原创出处:https://codepen.io/aaronchuo/pen/GLEed

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值