6.常用样式.html 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  6. <title>Document</title>
  7. <style>
  8. /*
  9. css样式中 后面的层级会覆盖前面的层级
  10. id选择器
  11. 写法:
  12. 在body里
  13. 开始标签中 id="xxx"
  14. 在style中
  15. #xxx {样式....}
  16. */
  17. #box {
  18. /* 样式 */
  19. width: 600px;
  20. height: 500px;
  21. /* background: red; */
  22. background: url("./images/img01.gif");
  23. /* background-repeat: no-repeat; */
  24. /* background-position: 20px 50px; */
  25. background: url('./images/img01.gif') no-repeat center;
  26. background-size: contain;
  27. }
  28. #box1 {
  29. width: 200px;
  30. height: 200px;
  31. background: yellow;
  32. }
  33. /*
  34. 背景 background:color image repeat position复合属性
  35. background-color 背景颜色
  36. background-image:url("路径") 背景图片
  37. background-repeat 背景图片重复方式
  38. repeat-x 水平重复
  39. repeat-y 垂直重复
  40. no-repeat 不重复
  41. background-position 背景图片位置
  42. background-size 背景图片尺寸
  43. cover 全覆盖
  44. contain 等比例放到最大
  45. */
  46. </style>
  47. </head>
  48. <body>
  49. <!-- id选择器 -->
  50. <div id="box">
  51. <!-- <div id="box1"></div> -->
  52. </div>
  53. </body>
  54. </html>