02.背景.html 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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: 500px;
  11. height: 500px;
  12. /*
  13. background-color 设置背景颜色
  14. */
  15. background-color: #bfa;
  16. /*
  17. background-image 设置背景图片
  18. -可以同时设置背景图片和背景颜色,这样背景颜色将会成为图片的背景色
  19. -如果背景的图片小于元素,则背景图片会自动在元素中平铺将元素铺满
  20. -如果背景的图片大于元素,将会有一部分背景无法完全显示
  21. -如果背景图片和元素一样大,则会直接正常显示
  22. */
  23. background-image: url('./images/1.png');
  24. /*
  25. background-repeat 用来设置背景的重复方式
  26. 可选值:
  27. repeat 默认值,背景会沿着X轴、y轴双方向重复
  28. repeat-x 沿着x轴方向重复
  29. repeat-y 沿着y轴方向重复
  30. no-repeat 背景图片不重复
  31. */
  32. background-repeat: no-repeat;
  33. /*
  34. background-position 用来设置背景图片的位置
  35. 设置方式:
  36. 通过top left right bottom center几个表示方位的词来设置背景图片的位置
  37. 使用方位词时,必须要同时指定两个值,如果只写一个值,
  38. 则第二个默认就是center
  39. 通过偏移量来指定背景图片的位置
  40. 水平方向的偏移量 垂直方向的偏移量
  41. */
  42. /* background-position: top; */
  43. background-position: 50px 50px;
  44. }
  45. </style>
  46. </head>
  47. <body>
  48. <div class="box1"></div>
  49. </body>
  50. </html>