5-1 CSS3背景 background-origin
本节编程练习不计算学习进度,请电脑登录imooc.com操作

CSS3背景 background-origin

设置元素背景图片的原始起始位置

语法:

background-origin : border-box | padding-box | content-box;

参数分别表示背景图片是从边框,还是内边距(默认值),或者是内容区域开始显示。

效果如下:

需要注意的是,如果背景不是no-repeat,这个属性无效,它会从边框开始显示。

任务

在右侧代码编辑器窗口的第14行,输入正确内容使背景从内容区域开始显示。

  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>背景原点</title>
  6. <style type="text/css">
  7. .wrap {
  8. width:220px;
  9. border:20px dashed #000;
  10. padding:20px;
  11. font-weight:bold;
  12. color:#000;
  13. background:#ccc url(http://static.mukewang.com/static/img/logo_index.png) no-repeat;
  14. background-origin: ?;
  15. position: relative;
  16. }
  17. .wrap span {
  18. position: absolute;
  19. left:0;
  20. top:0;
  21. }
  22. .content {
  23. height:80px;
  24. border:1px solid #333;
  25. }
  26. </style>
  27. </head>
  28. <body>
  29. <div class="wrap"><span>padding</span>
  30. <div class="content">content</div>
  31. </div>
  32. </body>
  33. </html>
下一节