css中background-origin属性的使用解析
前端  /  管理员 发布于 7年前   249
background-origin用来规定元素背景图像的相对定位位置,它有三个属性值:
1、border-box
border-box表示元素背景图像相对于border区域开始定位。
代码如下:
<!doctype html><html> <head> <style> *{margin:0;padding:0;}.box{width:430px;height:280px;margin:100px auto;background:url("fengjing.jpg") no-repeat;padding:5px;border:5px dotted #000;<br data-filtered="filtered">font-size:100px;font-weight:bold;background-origin:border-box;] </style> </head> <body> <div class="box "></div> </body></html>
效果如下:
从上图可以看出,元素的背景图像从边框区域开始定位。
2、padding-box
padding-box表示元素背景图像相对于padding区域开始定位。
代码如下:
<!doctype html><html> <head> <style> *{margin:0;padding:0;}.box{width:430px;height:280px;margin:100px auto;background:url("fengjing.jpg") no-repeat;padding:5px;border:5px dotted #000;<br data-filtered="filtered">font-size:100px;font-weight:bold;background-origin:padding-box;] </style> </head> <body> <div class="box "></div> </body></html>
效果如下:
从上图可以看出:元素背景图像从padding区域开始定位。
3、content-box
content-box表示元素背景图像相对于content区域开始定位。
代码如下:
<!doctype html><html> <head> <style> *{margin:0;padding:0;}.box{width:430px;height:280px;margin:100px auto;background:url("fengjing.jpg") no-repeat;padding:5px;border:5px dotted #000;<br data-filtered="filtered">font-size:100px;font-weight:bold;background-origin:content-box;] </style> </head> <body> <div class="box "></div> </body></html>
效果如下:
从上图可以看出:元素的背景图像初始位置从content区域开始定位。
总结,background-origin属性定义了背景图像的相对定位位置,这个位置可以用background-position来改变,而且元素背景图像的区域不会因此被限定住,只对元素背景图像起作用。如果元素使用background-attachment属性时,该属性会失效。
background-origin定义和用法
background-origin 属性规定 background-position 属性相对于什么位置来定位。
注释:如果背景图像的 background-attachment 属性为 "fixed",则该属性没有效果。
默认值: | padding-box |
---|---|
继承性: | no |
版本: | CSS3 |
JavaScript 语法: | object.style.backgroundOrigin="content-box" |
语法
background-origin: padding-box|border-box|content-box;
值 | 描述 | |
---|---|---|
padding-box | 背景图像相对于内边距框来定位。 | |
border-box | 背景图像相对于边框盒来定位。 | |
content-box | 背景图像相对于内容框来定位。 |
总结
以上所述是小编给大家介绍的css中background-origin属性的使用解析,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对站的支持!
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号