新增属性

  • 兼容性 IE9+ 浏览器支持, 但是不会影响页面布局,可以放心使用.

圆角边框(重点)

在 CSS3 中,新增了圆角边框样式,这样我们的盒子就可以变圆角了。 border-radius 属性用于设置元素的外边框圆角。

  • 语法: border-radius:length;
  • 参数值可以为数值百分比的形式
  • 如果是正方形,想要设置为一个圆,把数值修改为高度或者宽度的一半即可,或者直接写为 50%
  • 该属性是一个简写属性,可以跟四个值,分别代表左上角、右上角、右下角、左下角
  • 分开写:border-top-left-radius、border-top-right-radius、border-bottom-right-radius 和 border-bottom-left-radius

盒子阴影

我们可以使用 box-shadow 属性为盒子添加阴影。

  • 语法: box-shadow: h-shadow v-shadow blur spread color inset; | 值 | 描述 | | :—- | :—- | | h-shadow | 必需。水平阴影的位置。允许负值。 | | v-shadow | 必需。垂直阴影的位置。允许负值。 | | blur | 可选。模糊距离。 | | spread | 可选。阴影的尺寸。 | | color | 可选。阴影的颜色。 | | inset | 可选。将外部阴影 (outset) 改为内部(inset)阴影。 |
  • 实例: div{ box-shadow: 10px 10px 5px rgba(0, 0, 0, .3); }
  • outset: 默认不写的,写了会不起效果。
  • 盒子阴影不占用空间,不会影响其他盒子排列。

文字阴影

可以规定水平阴影、垂直阴影、模糊距离,以及阴影的颜色。

  • 语法: text-shadow: h-shadow v-shadow blur color; | 值 | 描述 | | :—- | :—- | | h-shadow | 必需。水平阴影的位置。允许负值。 | | v-shadow | 必需。垂直阴影的位置。允许负值。 | | blur | 可选。模糊距离。 | | color | 可选。阴影的颜色。 |

CSS3新增选择器

  • E:元素
  • att:属性
  • 类选择器、属性选择器、伪类选择器,权重为 10。

属性选择器

选择符 简介
E[att] 选择具有att属性的E元素
E[att = “val”] 选择具有att属性且属性等于 valE元素
E[att ^= “val”] 匹配具有att属性且值是以 val开头E元素
E[att $= “val”] 匹配具有att属性且值是以 val结尾E元素
E[att *= “val”] 匹配具有att属性且值中 含有valE元素
  • 代码解析
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>CSS3属性选择器</title>
  7. <style>
  8. input{
  9. display: block;
  10. margin-bottom: 20px;
  11. }
  12. /*E[att] 选择具有att属性的E元素
  13. **input[value] 选择具有value属性的input元素
  14. */
  15. input[value]{
  16. background-color: pink;
  17. }
  18. /*E[att = 'val'] 选择具有att属性且属性等于val的E元素
  19. **input[type = 'password'] 选择具有type属性且值等于val的input元素
  20. */
  21. input[type = 'password']{
  22. background-color: skyblue;
  23. }
  24. /*E[att ^= "val" 选择具有att属性且
  25. **E[att $= "val"] 选择具有att属性且是以val结尾的E元素
  26. **E[att *= "val" 选择具有att属性且包含val的E元素
  27. ** div[class ^= 'con'] 选择具有 class属性且是以 con开头 的div元素
  28. ** div[class $= 'con'] 选择具有 class属性且是以 con结尾 的div元素
  29. ** div[class *= 'con'] 选择具有 class属性且 包含con 的div元素
  30. */
  31. div[class ^= 'con']{
  32. background-color: pink;
  33. }
  34. div[class $= 'con']{
  35. background-color: skyblue;
  36. }
  37. div[class *= 'con']{
  38. font-size: 20px;
  39. }
  40. </style>
  41. </head>
  42. <body>
  43. <input type="text">
  44. <input type="text" value="具有value属性">
  45. <input type="text" name="" id="">
  46. <input type="password" name="" id="">
  47. <div class="con_1">具有con的开头</div>
  48. <div class="con_2">具有con的开头</div>
  49. <div class="con_3">具有con的开头</div>
  50. <div class="in_con">具有con的结尾</div>
  51. <div class="in_con">具有con的结尾</div>
  52. <div class="in_con_5">具有con</div>
  53. <div class="in_com_4">具有con</div>
  54. </body>
  55. </html>

结构伪类选择器

选择符 简介
E:first-child 匹配父元素的第一个子元素 E
E:last-child 匹配父元素最后一个子元素 E
E:nth-child(n)] 匹配父元素的第 n 个子元素 E ( n 可以是数字、关键字和公式)
E:first-of-type 指定类型的 E 的第一个
E:last-of-type 指定类型的 E 的最后一个
E:nth-of-type(n) 指定类型的 E 的第 n
  • nth-child(n)
  1. 数字的话从1开始
  2. 一般用的关键字:even偶数 odd奇数
  3. 公式:
    2n: 偶数 2n + 1: 奇数。
    5n: 5 10 15 …
    n + 5: 从第5个开始到最后一个
    -n + 5:5个,包含第5
    ······
  • 代码解析
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>结构伪类选择器</title>
  7. <style>
  8. /* child */
  9. /* 第一个 */
  10. div:first-child{
  11. background-color: pink;
  12. }
  13. /* 最后一个
  14. 因为child方法是先 排序(last-child),再寻找前面的 元素(div)这里最后一个是元素是span。
  15. 所以匹配不到 */
  16. div:last-child{
  17. background-color: pink;
  18. }
  19. /* 指定哪一个 nth-child(n) 选择这里 n = 3 所以配到了第三个 */
  20. div:nth-child(3){
  21. background-color: skyblue;
  22. }
  23. /* type */
  24. /* 第一个 */
  25. p:first-of-type{
  26. background-color: slategray;
  27. }
  28. /* 最后一个 */
  29. p:last-of-type{
  30. background-color: tomato;
  31. }
  32. /* 指定哪一个 nth-child(n) 选择这里 n = 2 所以配到了第2个 */
  33. p:nth-of-type(2){
  34. background-color: tomato;
  35. }
  36. span{display: block;}
  37. /* 公式的用法 */
  38. /* 选择偶数行: even 或者 2n */
  39. /* span:nth-of-type(even){
  40. background-color: turquoise;
  41. } */
  42. span:nth-of-type(2n){
  43. background-color: turquoise;
  44. }
  45. /* 选择奇数行: odd 或者 2n */
  46. span:nth-of-type(odd){
  47. background-color: skyblue;
  48. }
  49. /* span:nth-of-type(2n+1){
  50. background-color: skyblue;
  51. } */
  52. /* 包含第六个的后面所有个数 */
  53. ul li:nth-child(n + 6){
  54. background-color: skyblue;
  55. }
  56. /* 包含第四个的前面四个 */
  57. ul li:nth-child(-n + 4){
  58. background-color: turquoise;
  59. }
  60. </style>
  61. </head>
  62. <body>
  63. <!-- <input type="password" name="" id=""> --> <!-- child方法 -->
  64. <div>div的第1个</div>
  65. <div>div的第2个</div>
  66. <div>div的第3个</div>
  67. <div>div的第4个</div>
  68. <div>div的第5个</div>
  69. <div>div的最后一个</div>
  70. <p>p的第1个</p>
  71. <p>p的第2个</p>
  72. <p>p的第3个</p>
  73. <p>p的第4个</p>
  74. <p>p的第5个</p>
  75. <p>p的最后一个</p>
  76. <span>span的第1个</span>
  77. <span>span的第2个</span>
  78. <span>span的第3个</span>
  79. <span>span的第4个</span>
  80. <span>span的第5个</span>
  81. <span>span的最后一个</span>
  82. <ul>
  83. <li>li的第1个</li>
  84. <li>li的第2个</li>
  85. <li>li的第3个</li>
  86. <li>li的第4个</li>
  87. <li>li的第5个</li>
  88. <li>li的第6个</li>
  89. <li>li的第7个</li>
  90. <li>li的最后一个</li>
  91. </ul>
  92. </body>
  93. </html>

nth-chil与nth-of-type的区别

  • E:nth-chil
    把所有的盒子排序
    执行时先看 nth-chil(n) 再判断 E,先选择第几个,再判断元素E
  • E:nth-of-type
    把指定元素的盒子排序
    执行先判断 E(指定的元素) 再看 nth-of-type(n),先判断元素E,再选择第几个

伪元素选择器

新创建的这个元素在文档树中是找不到的,所以我们称为伪元素

  • 行内元素
  • 必须有 content 属性
  • 伪元素选择器标签选择器 一样,权重1 | 选择符 | 简介 | | :—- | :—- | | ::before | 在元素内部的前面插入内容 | | ::after | 在元素内部的后面插入内容 |

通常用于配合字体图标使用,和鼠标经过样式使用,还有清除浮动时使用。

  • 代码解析
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>伪类选择器</title>
  7. <style>
  8. div{
  9. width: 500px;
  10. height: 500px;
  11. background-color: pink;
  12. }
  13. div:hover::before{
  14. content: '';/* 必须要有的属性 */
  15. display: inline-block; /* 因为是行内元素没有宽高,改成行内块 */
  16. width: 100%;
  17. height: 100%;
  18. background: url(images/bg.jpg);
  19. filter: blur(8px); /* 模糊属性,值越大越模糊 */
  20. }
  21. </style>
  22. </head>
  23. <body>
  24. <div>
  25. </div>
  26. </body>
  27. </html>

CSS3 盒子模型

CSS3 中可以通过 box-sizing 来指定盒模型。有 content-box 值和 border-box这是个非常方便的属性,可以解决使用内外边距时会撑大容器(盒子)的问题

  • 关于盒子组成分成两种情况
  1. box-sizing: content-box (以前默认的) 盒子大小为: width + padding + border
  2. box-sizing: border-box 盒子大小为: width (前提paddingborder不会超过width宽度)

CSS3新增特效

滤镜filter

filter CSS属性将模糊或颜色偏移等图形效果应用于元素。

  • 语法:filter: 函数();
  • 例(模糊处理): filter: blur(3px); blur 数值越大越模糊。通常用于模糊背景图片等。

calc 函数

用来计算子元素的大小,实现子元素的大小会随着父元素的改变而改变。

  • **面可以使用 + - / 来进行计算。
  • 写法:width: calc(100% - 80px);
  • 这是一个进度条
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>伪类选择器</title>
  7. <style>
  8. .bar {
  9. /* box-sizing: border-box; */
  10. position: relative;
  11. margin-top: 50px;
  12. width: 250px;
  13. height: 25px;
  14. border: 2px solid rgb(90, 88, 88);
  15. border-radius: 10px;
  16. padding: 1px;
  17. }
  18. .bar_in {
  19. border-top-left-radius: 10px;
  20. border-bottom-left-radius: 10px;
  21. height: calc(100%);
  22. width: calc(100% / 2);
  23. background-color: skyblue;
  24. transition: all .6s;
  25. }
  26. .bar:hover .bar_in {
  27. width: calc(100%);
  28. border-radius: 10px;
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div class="bar">
  34. <div class="bar_in"></div>
  35. </div>
  36. </body>
  37. </html>

过渡(重点)

过渡(transition)是CSS3中具有颠覆性的特征之一,我们可以在不使用 Flash 动画或 JavaScript 的情况下,当元素从一种样式变换为另一种样式时为元素添加效果。 经常和 :hover 一起搭配使用。

  • 语法:transition: 要过渡的属性 花费时间 运动曲线 何时开始;
  • 过度的属性:必填。例如,宽、高、背景颜色等都可以,也可以写 all(代表所有属性都变化过渡)
  • 花费时间:必填。 单位是必须写单位) 比如 0.5s,用来确定动画过渡需要花费的时间。
  • 运动曲线: 默认是 ease (可以省略)
  • 何时开始 单位是必须写单位)可以设置延迟触发时间 默认是 0s(可以省略)

过渡案例的使用可参考上面的代码。

2D

转换(transform) 是SS3中具有颠覆性的特征之一,可以实现元素的位移、 旋转、 缩放等效果。 更详细使用可查看转载文章 2D 转换包括 移动(translate) 旋转 (rotate) 缩放 (scale)

  • 2D转化是在改变二维平面坐标位置形状。
    • 二维坐标 x 轴:越往右越大(与数学相同)
    • 二维坐标 y 轴:越往下越大(与数学相反)
  • 2D 搭配 过渡(transition) 使用效果更佳,可以做简单的动画效果了。
  • 2D 里面还有一个属性可以设置元素转换的中心点 (默认是盒子的中心点)
    • 语法:transform-origin:(x,y) x y 是在二维平面坐标位置。(可以跟方位名词)

移动 (translate)

2D 里面的移动 (translate) 类似于定位(position)一样。 最大优势:也就是不影响其它元素的位置,缺点:对行内元素没有效果。 移动 (translate) 可以用于盒子的垂直居中对齐。不用写具体值,搭配(calc) 效果更好。 position: absolute; top: 50%; left: 50%; transform: translate(-50%,-50%);

语法:

  • transform: translate(x, y); 移动x轴与y轴,不能省略(两个值都要填)。
  • transform: translateX(n); x轴
  • transform: translateY(n); y轴

旋转 (rotate)

2D 里面的 旋转 是指在二维平面内 顺时针 / 逆时针 的旋转。 可以用来做三角形。哈哈哈哈 配合,中心点 transform-origin:(x,y) 使用效果更佳。(默认中心旋转)

语法:

  • transform: rotate(度数); 度数为正顺时针。 (单位是:deg)

缩放 (scale)

2D 里面的 缩放 就是放大缩小的作业啦。 优势:不影响其它盒子 配合,中心点 transform-origin:(x,y) 使用效果更佳。(默认中心放大)

语法:

  • transform: scale(x,y); (输入值 不需要单位不能是负数0.x/0.y可以省略不写0)
  • transform: scale(n); x轴与y轴 相同倍数
  • transform: scaleX(n); x轴
  • transform: scaleY(n); y轴

总结

2D 更多 过渡(transition) 使用效果更佳,可以做简单的动画效果了。 比如鼠标经过,移动一下,旋转一下,放大/缩小一下这样。(也可以同时两三个效果) 同时使用多个转换,其格式为: transform: tanslate() rotate() scale(),顺序会影响转换效果

  • 代码练习(几个简单的小盒子)
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>2D转换</title>
  7. <style>
  8. body{
  9. margin: 100px 700px;
  10. }
  11. p{
  12. font-size: 30px;
  13. line-height: 400px;
  14. text-align: center;
  15. }
  16. div {
  17. position: relative;
  18. margin-bottom: 100px;
  19. width: 400px;
  20. height: 400px;
  21. background-color: skyblue;
  22. transition: all 1s;
  23. }
  24. .con div{
  25. /* 通过 absolute绝对布局 和 transform: translate()移动 实现盒子的居中 */
  26. margin: 0;
  27. position: absolute;
  28. top: 50%;
  29. left: 50%;
  30. width: calc(50%);
  31. height: calc(50%);
  32. transform: translate(-50%,-50%);
  33. background-color: pink;
  34. }
  35. .con div p{
  36. margin: 0;
  37. font-size: 15px;
  38. line-height: 200px;
  39. }
  40. .con:hover {
  41. /* transform: translate(x, y); 移动x轴与y轴,不能省略。
  42. ** 优点:不用影响到其它元素的位置
  43. ** 单独写法:
  44. ** transform: translateX(n); x轴
  45. ** transform: translateY(n); y轴
  46. */
  47. transform: translate(20px, 10%);
  48. }
  49. .con1{
  50. /* transform-origin : left 0px; */
  51. }
  52. .con1:hover{
  53. /* transform: scale(x,y); 中心放大,x,y 放大倍数,可以省略(即是两个值一样)
  54. ** 优势:不用影响其它盒子的位置,也可以设置缩放中心点
  55. ** 单独写法:
  56. ** transform: scaleX(n); x轴
  57. ** transform: scaleY(n); y轴
  58. */
  59. transform: scale(1.2);
  60. }
  61. .con2{
  62. /* transform: rotate(n); 中心旋转,正数正旋转,负数负旋转(单位是 deg)
  63. ** 默认是中心点 (50%,50%)/(center,center)
  64. ** 转换中心点 transform-origin : x y; 参数可以百分比、像素或者是方位名词,空格隔开 */
  65. transform-origin : left 0px;
  66. }
  67. .con2:hover{
  68. transform: rotate(-360deg);
  69. }
  70. /* 通过 rotate 制作三角形箭头 */
  71. .con2::after{
  72. content: '';
  73. position: absolute;
  74. top: 47%;
  75. right: 23%;
  76. width: 15px;
  77. height: 15px;
  78. border-right: 2px solid #000;
  79. border-bottom: 2px solid #000;
  80. transform: rotate(45deg);
  81. }
  82. .con2:hover::after{
  83. transform: rotate(-135deg);
  84. }
  85. .con2-1{
  86. overflow: hidden;
  87. }
  88. .con2-1::after{
  89. content: "rotate旋转案例";
  90. display: block;
  91. width: calc(100%);
  92. height: calc(100%);
  93. font-size: 25px;
  94. text-align: center;
  95. line-height: 400px;
  96. background-color: hotpink;
  97. transform: rotate(180deg);
  98. transform-origin: left bottom;
  99. transition: all 1s;
  100. }
  101. .con2-1:hover::after{
  102. transform: rotate(0deg);
  103. }
  104. .con-1{
  105. transition: all 1s;
  106. }
  107. .con-1:hover{
  108. /* 注意书写顺序,应该吧 translate 放在最前面,不然会出现混乱 */
  109. transform: translate(200px,50px) scale(1.2) rotate(360deg) ;
  110. }
  111. </style>
  112. </head>
  113. <body>
  114. <div class="con">
  115. <div>
  116. <p>translate移动和实现居中</p>
  117. </div>
  118. </div>
  119. <div class="con1">
  120. <p>scale放大</p>
  121. </div>
  122. <div class="con2">
  123. <p>rotate旋转</p>
  124. </div>
  125. <div class="con2-1">
  126. <!-- <p>rotate旋转</p> -->
  127. </div>
  128. <div class="con-1">
  129. <p>综合案例</p>
  130. </div>
  131. </body>
  132. </html>

动画

动画(animation) 是CS3中具有颠覆性的特征之一,能通过设置多个节点来精确控制一个或一组动画。 可以理解为过渡的加强版,比过渡多了更多的变化、更详细的控制,连续播放暂停等功能。 动画可以分为两步:定义动画调用(使用)动画

定义动画

定义动画通过 keyframes 动画开始状态 0% (from) 和动画结束状态 100% (to) % 可以写1-100,通过时间划分

  1. /* 定义动画 */
  2. @keyframes 动画名称 {
  3. /* from 和 to 等价于 0% 100% */
  4. /* 动画开始状态 */
  5. 0% {
  6. transform: translateX(0px);
  7. }
  8. /* 动画结束状态 */
  9. 100% {
  10. transform: translateX(1500px);
  11. }
  12. }

调用(使用)动画

通过animation开头的各种属性设置动画的属性。 必须要有的属性: 调用动画:animation-name: 动画名称;持续时间: animation-duration: 时间;

  • 常用属性 | 属性 | 描述 | | —- | —- | | @keyframes | 定义动画。 | | animation | 所有动画属性的简写属性,除了animation-play- state属性 (暂停) | | animation-name | 必需! 调用 @keyframes 动画的名称。 | | animation-duration | 必需! 动画完成个周期所花费的s秒或ms毫秒, 默认是0。 | | animation-timing-function | 动画的速度曲线,默认是 easelinear 匀速 | | animation- delay | 动画暂停多久开始,默认是0。单位是s秒 | | animation-iteration-count | 动画被播放的次数,默认是1(次),还有infinite(重复) | | animation-direction | 动画是否在结束后逆向播放,默认是normal , alternate 逆播放 | | animation-play-state | 定义动画是否正在运行暂停。默认是running(运行),还有paused(暂停)。 | | animation-fill-mode | 动画结束后保持的状态,默认是回到起始backwards,保持forwards |
  • 速度曲线 | 属性值 | 描述 | | —- | —- | | linear | 开头到结尾。匀速 | | ease | 默认 低速开始,然后加快,在结束前变慢。 | | ease-in | 低速开始 | | ease-out | 低速结束 | | ease-in-out | 低速开始和结束 | | steps() | 指定了时间函数中的间隔数量(步长) |

步长挺重要的。

  • 开发中最常用的是复合的写法(animation:(前两个不能省略)
    • animation: name duration timing-function delay iteration-count direction fill-mode;
    • animation: 动画名称 持续时间 运动曲线 何时开始 播放次数 是否反方向 动画结束状态
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>动画练习</title>
  7. <style>
  8. /* 定义动画 */
  9. @keyframes move {
  10. /* from 和 to 等价于 0% 100% */
  11. /* 动画开始状态 */
  12. 0% {
  13. transform: translateX(0px);
  14. }
  15. /* 动画结束状态 */
  16. 100% {
  17. transform: translateX(1500px);
  18. }
  19. }
  20. @keyframes move1 {
  21. 0% {
  22. transform: translate(0, 0);
  23. }
  24. 35% {
  25. transform: translate(1500px, 0);
  26. }
  27. 50% {
  28. transform: translate(1500px, 500px);
  29. }
  30. 85% {
  31. transform: translate(0, 500px);
  32. }
  33. 100% {
  34. transform: translate(0, 0);
  35. }
  36. }
  37. div {
  38. width: 200px;
  39. height: 200px;
  40. background-color: skyblue;
  41. }
  42. .wjz-dh01 {
  43. /* 调用动画 */
  44. animation-name: move1;
  45. /* 持续时间 单位是秒(s) 毫秒(ms) */
  46. animation-duration: 6s;
  47. /* 运动曲线 默认值: ease */
  48. animation-timing-function: ease;
  49. /* 延时开始 默认值: 0s */
  50. animation-delay: 0s;
  51. /* 重复次数 默认值: 1 iteration 重复的 count 次数 infinite 无限*/
  52. animation-iteration-count: infinite;
  53. /* 是否反方向播放 默认是: normal 反方向 alternate*/
  54. animation-direction: normal;
  55. /* 动画结束后的状态 默认是:backwards 停留在结束的状态 forwards */
  56. /* animation-fill-mode: backwards; */
  57. /* 简写(前两个不能省略) animation: 动画名称 持续时间 运动曲线 何时开始 播放次数 是否反方向 动画结束状态*/
  58. animation: move1 6s linear 0s infinite alternate backwards;
  59. /* linear匀速状态 */
  60. /* animation: name duration timing-function delay iteration-count direction fill-mode; */
  61. }
  62. .wjz-dh01:hover {
  63. /* 动画时候暂停 默认是:running(运行) 停止 paused*/
  64. animation-play-state: paused;
  65. }
  66. .wjz-dh02 {
  67. position: relative;
  68. margin: 100px auto;
  69. }
  70. .wjz-dh02 .city {
  71. position: absolute;
  72. right: 40px;
  73. top: 30px;
  74. width: 50px;
  75. height: 50px;
  76. /* background-color: slategrey; */
  77. }
  78. .wjz-dh02 .one{
  79. right: 80px;
  80. top: 100px;
  81. }
  82. .wjz-dh02 .dotted{
  83. position: absolute;
  84. top: 50%;
  85. left: 50%;
  86. transform: translate(-50%,-50%);
  87. width: 8px;
  88. height: 8px;
  89. border-radius: 50%;
  90. z-index: 1;
  91. background-color: hotpink;
  92. }
  93. .wjz-dh02 div[class ^='pulse'] {
  94. /* 保证波纹垂直居中 */
  95. position: absolute;
  96. top: 50%;
  97. left: 50%;
  98. transform: translate(-50%,-50%);
  99. /* 保证波纹垂直居中 */
  100. width: 8px;
  101. height: 8px;
  102. border-radius: 50%;
  103. box-shadow: 0 0 12px red;
  104. /* 简写(前两个不能省略) animation: 动画名称 持续时间 运动曲线 何时开始 播放次数 是否反方向 动画结束状态*/
  105. /* animation: name duration timing-function delay iteration-count direction fill-mode; */
  106. animation: pules 1.2s linear infinite backwards;
  107. }
  108. .pulse2{
  109. animation-delay: 0.4s!important;
  110. }
  111. .pulse3{
  112. animation-delay: 0.8s!important;
  113. }
  114. @keyframes pules{
  115. 0%{
  116. }
  117. 50%{
  118. /* transform: scale(2); 不能用 scale 不仅阴影变大,还会偏移了 */
  119. width: 30px;
  120. height: 30px;
  121. opacity: 1;
  122. }
  123. 100%{
  124. width: 70px;
  125. height: 70px;
  126. opacity: 0;
  127. }
  128. }
  129. .p {
  130. position: absolute;
  131. top: 230px;
  132. left: 40%;
  133. width: 0;
  134. height: 40px;
  135. font-size: 30px;
  136. background-color: #fff;
  137. white-space: nowrap; /* 一行显示 */
  138. overflow: hidden; /* 超出隐藏 */
  139. /* 简写(前两个不能省略) animation: 动画名称 持续时间 运动曲线 何时开始 播放次数 是否反方向 动画结束状态*/
  140. /* steps() 步长,分成多少步来走 linear 匀速 ease默认 */
  141. animation: wz 5s steps(16) infinite;
  142. }
  143. @keyframes wz{
  144. 0% {}
  145. 100% {width: 480px;}
  146. }
  147. </style>
  148. </head>
  149. <body>
  150. <div class="wjz-dh01"></div>
  151. <div class="wjz-dh02">
  152. <div class="city">
  153. <div class="dotted"></div>
  154. <div class="pulse1"></div>
  155. <div class="pulse2"></div>
  156. <div class="pulse3"></div>
  157. </div>
  158. <div class="city one">
  159. <div class="dotted"></div>
  160. <div class="pulse1"></div>
  161. <div class="pulse2"></div>
  162. <div class="pulse3"></div>
  163. </div>
  164. </div>
  165. <div class="p">这是一个用了步长来显示的一句话</div>
  166. </body>
  167. </html>

3D

通过近大远小的的原理实现3D效果。在网页中通过三维坐标系实现,就是在二维的基础上加上Z轴,往外面是正值。 3D也就是在2D的基础上多多加一个Z轴3D是建立在2D的基础上的,2D基础一定要牢靠

  • 3D位移 translate3d(x,y,z)(复合写法)
    • 在二D的基础上多加一个Z轴的移动方向:translateZ(n) 单位也是 px
  • 3D旋转 rotate3d(x,y,z) 左手定则,拇指对着正方向,四手指弯曲方向为正。
    • 沿着X轴的旋转方向:transform:rotateX(n) 单位也是 deg
    • 沿着Y轴的旋转方向:transform:rotateY(n) 单位也是 deg
    • 沿着Z轴的旋转方向:transform:rotateZ(n) 单位也是 deg
  • 透视 perspective:距离 在2D平面产生近大远小视觉立体,但是只是效果二维的 单位是 px
    • 数值越小,代表离我们人体越近,显示得也越大。
  • 3D呈现 transfrom-style 控制子元素是否开启三维立体环境
    • transform-tyle: flat; 子元素不开启3D立体效果,默认值
    • transform-style: preserve-3d; 子元素开启3D立体效果。
  • 3D木马效果案例
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>3D旋转木马</title>
  7. <style>
  8. body{
  9. /* 实现3D效果,近大远小的效果 */
  10. perspective: 800px;
  11. }
  12. section{
  13. position: relative;
  14. margin: 200px auto;
  15. width: 250px;
  16. height: 300px;
  17. /* transition: all 5s; */
  18. /* 让儿子保持3D效果 */
  19. transform-style: preserve-3d;
  20. animation: move 10s linear infinite;
  21. }
  22. section img{
  23. width: 100%;
  24. height: 100%;
  25. }
  26. section:hover{
  27. animation-play-state: paused;
  28. }
  29. section div{
  30. position: absolute;
  31. top: 0;
  32. left: 0;
  33. width: 100%;
  34. height: 100%;
  35. }
  36. section div img{
  37. width: 100%;
  38. height: 100%;
  39. }
  40. section div:nth-child(1){
  41. transform: translateZ(300px);
  42. }
  43. section div:nth-child(2){
  44. transform: rotateY(60deg) translateZ(300px);
  45. }
  46. section div:nth-child(3){
  47. transform: rotateY(120deg) translateZ(300px);
  48. }
  49. section div:nth-child(4){
  50. transform: rotateY(180deg) translateZ(300px);
  51. }
  52. section div:nth-child(5){
  53. transform: rotateY(240deg) translateZ(300px);
  54. }
  55. section div:nth-child(6){
  56. transform: rotateY(300deg) translateZ(300px);
  57. }
  58. @keyframes move{
  59. 0%{transform: rotateY(0deg)}
  60. 100%{transform: rotateY(360deg);}
  61. }
  62. </style>
  63. </head>
  64. <body>
  65. <section>
  66. <div><img src="images/0.jfif" alt="123"></div>
  67. <div><img src="images/01.jpg" alt=""></div>
  68. <div><img src="images/0.jfif" alt=""></div>
  69. <div><img src="images/0.jfif" alt=""></div>
  70. <div><img src="images/0.jfif" alt=""></div>
  71. <div><img src="images/0.jfif" alt=""></div>
  72. <div><img src="images/0.jfif" alt=""></div>
  73. </section>
  74. </body>
  75. </html>