博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
【css3学习系列】之box-shadow,radial-gradient,linear-gradient
阅读量:7031 次
发布时间:2019-06-28

本文共 2798 字,大约阅读时间需要 9 分钟。

Talk is cheap.Show me the code.

1.box-shadow

clipboard.png

.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

.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

【注】: 拉面原创出处:

转载地址:http://dpgxl.baihongyu.com/

你可能感兴趣的文章
仿淘宝头像上传功能(一)——前端篇。
查看>>
Eclipse通过集成svn实现版本控制
查看>>
OS开发过程中常用开源库
查看>>
关于在多个UItextield切换焦点
查看>>
hdu 2768
查看>>
git记住用户名密码
查看>>
ElasticSearch(2)-安装ElasticSearch
查看>>
从mysql数据表中随机取出一条记录
查看>>
ORACLE 锁表处理,解锁释放session
查看>>
深海机器人问题
查看>>
正则表达式(括号)、[中括号]、{大括号}的区别小结
查看>>
88.NODE.JS加密模块CRYPTO常用方法介绍
查看>>
java.net.ProtocolException: Exceeded stated content-length of: '13824' bytes
查看>>
asp.net 连接 oracle10g 数据库
查看>>
C 入门 第十一节
查看>>
HTML简单的注册页面搭建
查看>>
【06】Vue 之 组件化开发
查看>>
Docker 安装
查看>>
多数据库数据导入
查看>>
[AVR]高压并行编程---基础知识
查看>>