01.线性渐变.html 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  7. <title>线性渐变</title>
  8. <style>
  9. .box1{
  10. width: 200px;
  11. height: 200px;
  12. /* background-color: #bfa; */
  13. margin: 200px auto;
  14. /*
  15. 通过渐变,可以设置一些复杂的背景颜色,可以实现从一个颜色向其他颜色过渡的效果
  16. 渐变是图片,需要通过background-image来设置
  17. 线性渐变:颜色沿着一条直线发生变化
  18. linear-gradient()
  19. linear-gradient(red,yellow):表示红色在开头,黄色在结尾,中间是过渡区域
  20. -线性渐变的开头,我们可以指定一个渐变的方向
  21. to left
  22. to right
  23. to bottom
  24. to top
  25. xxxdeg deg表示度数
  26. turn 表示圈
  27. -渐变可以同时指定多个颜色,多个颜色默认情况下平均分布
  28. 也可以手动指定渐变的分布情况
  29. repeating-linear-gradient():可以平铺的线性渐变
  30. */
  31. /* background-image: linear-gradient(red,yellow); */
  32. /* background-image: linear-gradient(to right,red,yellow); */
  33. /* background-image: linear-gradient(180deg,red,yellow); */
  34. /* background-image: linear-gradient(to top left,red,yellow); */
  35. /* background-image: linear-gradient(.25turn,red,yellow); */
  36. /* background-image: linear-gradient(to right,red,yellow,#bfa,orange); */
  37. /* background-image: linear-gradient(red 50px,yellow 70px); */
  38. background-image: repeating-linear-gradient(red 50px,yellow 100px);
  39. /* 上面一行代码的效果等同于下面的这条 */
  40. background-image: repeating-linear-gradient(red 0px,yellow 50px);
  41. }
  42. </style>
  43. </head>
  44. <body>
  45. <div class="box1"></div>
  46. </body>
  47. </html>