码迷,mamicode.com
首页 > Web开发 > 详细

css中background-origin属性的使用

时间:2018-03-30 21:53:10      阅读:376      评论:0      收藏:0      [点我收藏+]

标签:src   图像   size   jpg   失效   com   att   .com   border   

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;
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;
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;
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属性时,该属性会失效。

css中background-origin属性的使用

标签:src   图像   size   jpg   失效   com   att   .com   border   

原文地址:https://www.cnblogs.com/okgoodman/p/8678267.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!