背景图原点指的是 背景图定位的时候 0 0(坐标轴的原点) 所默认的位置
如果图片平铺,那么border-box区域都是图片可以显示的区域
background-origin 改变背景图原点:
- background-origin: padding-box(背景图以padding左上角为原点从padding左上角开始显示) ------ 默认原点(但是如果图片没有设置no-repeat 边框里也会显示背景图片 不过是图片平铺的部分 如果设置了no-repeat 图片超出的部分也会在边框内显示)
div {
width: 500px;
height: 500px;
padding: 50px;
border: 20px dotted #ccc;
background: url(./img/jiufen.jpg) 0 0 no-repeat;
background-origin: padding-box;
}

div {
width: 500px;
height: 500px;
padding: 50px;
border: 20px dotted #ccc;
background: url(./img/jiufen.jpg) 0 0 repeat;
background-origin: padding-box;
}

- background-origin: content-box(背景图以内容区域左上角为原点在内容区域显示)
div {
width: 500px;
height: 500px;
padding: 50px;
border: 20px dotted #ccc;
background: url(./img/jiufen.jpg) 0 0 no-repeat;
background-origin: content-box;
}

- background-origin: border-box(背景图以外边框左上角为原点从边框左上角开始显示)
div {
width: 500px;
height: 500px;
padding: 50px;
border: 20px dotted #ccc;
background: url(./img/jiufen.jpg) 0 0 no-repeat;
background-origin: border-box;
}

本文详细解析了CSS中背景图原点(background-origin)属性的使用方法,包括padding-box、content-box及border-box三种定位方式的区别与应用场景,帮助读者掌握更精确的背景图定位技巧。
1225

被折叠的 条评论
为什么被折叠?



