CSS属性(背景属性)

た 入场券 2021-12-24 01:37 567阅读 0赞

1.背景属性

1468469-20190106144542211-773634552.png

1468469-20190106151658909-1660361908.png

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>05背景相关属性示例</title>
  6. <style>
  7. /* 背景颜色 */
  8. .c0 {
  9. background-color: red;
  10. }
  11. /* 背景图片 */
  12. /*.c1 {
  13. */
  14. /*width: 600px;*/
  15. /*height: 600px;*/
  16. /*border: 1px solid black; !* 边框,1像素,颜色是黑色 *!*/
  17. /*background-image: url("huluwa.png");*/
  18. /*background-repeat: no-repeat; !* 背景图片不平铺 *!*/
  19. /*!*background-position: center; !* 背景图片在中间区域,也可用50% 50% *!*!*/
  20. /*!*background-position: 50% 50%;*!*/
  21. /*background-position: 200px 200px; !* 向x轴和y轴各偏移200像素*!*/
  22. /*}*/
  23. /* 简写上面的.c1 */
  24. .c1 {
  25. width: 600px;
  26. height: 600px;
  27. border: 1px solid black; /* 边框,1像素,颜色是黑色 */
  28. background: url("huluwa.png") no-repeat 50% 50%; /* 简写成一条 */
  29. }
  30. </style>
  31. </head>
  32. <body>
  33. <div class="c0">我是div</div>
  34. <div class="c1"></div>
  35. </body>
  36. </html>

1468469-20190106151722516-1435304882.png

(1)一个鼠标滚动背景图不动的例子

  1. <!DOCTYPE html>
  2. <html lang="zh-CN">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>06背景不动效果示例</title>
  6. <style>
  7. .c1 {
  8. height: 500px;
  9. background-color: red;
  10. }
  11. .c2 {
  12. height: 500px;
  13. background: url("huluwa.png") no-repeat center;
  14. background-attachment: fixed; /* 将背景图片固定住,这样在鼠标上限滚动时,这个图片固定住 */
  15. }
  16. .c3 {
  17. height: 500px;
  18. background-color: green;
  19. }
  20. </style>
  21. </head>
  22. <body>
  23. <div class="c1"></div>
  24. <div class="c2"></div>
  25. <div class="c3"></div>
  26. </body>
  27. </html>

转载于:https://www.cnblogs.com/whylinux/p/10229049.html

发表评论

表情:
评论列表 (有 0 条评论,567人围观)

还没有评论,来说两句吧...

相关阅读