当前位置:Gxlcms > css > background-repeat属性怎么用

background-repeat属性怎么用

时间:2021-07-01 10:21:17 帮助过:53人阅读

CSS的background-repeat属性是用来设置背景图像如何平铺的。background-repeat:repeat-x表示只有水平位置会重复背景图像;background-repeat:repeat-y表示只有垂直位置会重复背景图像。

CSS background-repeat属性

作用:设置是否及如何重复背景图像。

基本语法:

background-repeat:repeat|repeat-x|repeat-y|no-repeat;

repeat:默认值,背景图像将向垂直和水平方向重复。

repeat-x:只有水平位置会重复背景图像。

repeat-y:只有垂直位置会重复背景图像。

no-repeat:设置背景图片不会重复。

说明:background-repeat 属性定义了图像的平铺模式。从原图像开始重复,原图像由 background-image 定义,并根据 background-position 的值放置。

CSS background-repeat属性的使用示例

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>菜鸟教程(runoob.com)</title>
  6. <style>
  7. .demo1{
  8. width: 400px;
  9. height: 150px;
  10. border: 1px solid red;
  11. background-image:url('https://img.php.cn/upload/article/000/000/024/5c6a4428ea867709.png');
  12. background-repeat:repeat;
  13. }
  14. .demo2{
  15. width: 400px;
  16. height: 100px;
  17. border: 1px solid red;
  18. background-image:url('https://img.php.cn/upload/article/000/000/024/5c6a4428ea867709.png');
  19. background-repeat:no-repeat;
  20. }
  21. .demo3{
  22. width: 400px;
  23. height: 150px;
  24. border: 1px solid red;
  25. background-image:url('https://img.php.cn/upload/article/000/000/024/5c6a4428ea867709.png');
  26. background-repeat:repeat-x;
  27. }
  28. .demo4{
  29. width: 400px;
  30. height: 400px;
  31. border: 1px solid red;
  32. background-image:url('https://img.php.cn/upload/article/000/000/024/5c6a4428ea867709.png');
  33. background-repeat:repeat-y;
  34. }
  35. </style>
  36. </head>
  37. <body>
  38. <h3>repeat设置背景图片向垂直和水平方向重复</h3>
  39. <div class="demo1"></div>
  40. <h3>no-repeat设置背景图片不重复</h3>
  41. <div class="demo2"></div>
  42. <h3>repeat-x设置背景图片向水平方向重复</h3>
  43. <div class="demo3"></div>
  44. <h3>repeat-y设置背景图片向垂直方向重复</h3>
  45. <div class="demo4"></div>
  46. </body>
  47. </html>

效果图:

1550471326915227.jpg

1550471332509829.jpg

以上就是本篇文章的全部内容,希望能对大家的学习有所帮助。

以上就是background-repeat属性怎么用的详细内容,更多请关注Gxl网其它相关文章!

人气教程排行