border和background区别(css中background-origin属性的使用解析)
border和background区别
css中background-origin属性的使用解析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" alt="border和background区别(css中background-origin属性的使用解析)" border="0" />
效果如下:
从上图可以看出,元素的背景图像从边框区域开始定位。
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" alt="border和background区别(css中background-origin属性的使用解析)" border="0" />
效果如下:
从上图可以看出:元素背景图像从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" alt="border和background区别(css中background-origin属性的使用解析)" border="0" />
效果如下:
从上图可以看出:元素的背景图像初始位置从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属性的使用解析,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对开心学习网网站的支持!
热门推荐
- 搭建php和mysql的运行环境(Windows环境开发PHP完整配置教程Apache+Mysql+PHP)
- docker部署golang(如何使用Docker部署Go Web应用的实现)
- web安全漏洞怎么解决(Web服务器常见8种安全漏洞)
- canvas绘制渐变图形(Canvas实现放大镜效果完整案例分析附代码)
- 怎么把织梦的dede改掉(织梦dedecms 提示 body has not allow words 问题解决)
- css怎么给背景颜色设置模糊(CSS设置背景图片模糊内容不模糊的解决方法)
- centos7.6 安装docker(Centos7安装Docker2020最新亲测可用,直接复制粘贴即可)
- laravel 用户登录认证(Laravel5.5 实现后台管理登录的方法自定义用户表登录)
- python中什么是迭代器(一篇文章彻底搞懂Python中可迭代Iterable、迭代器Iterator与生成器Generator的概)
- docker的漏洞(一次docker错误的耗时排查过程记录)