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属性的使用的更多相关文章

  1. css中background背景属性概

    css中background背景属性概 background:url(背景图片路径)  no-repeat;/*不重复默认在左上方*/background:url(背景图片路径)  no-repeat ...

  2. css中background背景属性概述

    background:url(背景图片路径) no-repeat;/*不重复默认在左上方*/ background:url(背景图片路径) no-repeat center;/*不重复背景图片中间显示 ...

  3. Css中的Position属性

    Css中的Position属性 Css属性在线查询地址: http://www.css88.com/book/css/properties/index.htm CSS 中的 position 属性 在 ...

  4. 深入理解css中的margin属性

    深入理解css中的margin属性 之前我一直认为margin属性是一个非常简单的属性,但是最近做项目时遇到了一些问题,才发现margin属性还是有一些“坑”的,下面我会介绍margin的基本知识以及 ...

  5. 理解与应用css中的display属性

    理解与应用css中的display属性 display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none block inline inline-block inherit 下面, ...

  6. CSS中的display属性(none,block,inline,inline-block,inherit)

    css中的display属性(none,block,inline,inline-block,inherit) display属性是我们在前端开发中常常使用的一个属性,其中,最常见的有: none bl ...

  7. 前端CSS-font属性,超链接的美化,css精灵,background综合属性

    前端CSS-font属性,超链接的美化,css精灵,background综合属性 1. font属性 使用font属性,能够将字号.行高.字体,能够一起设置. font:14px/24px " ...

  8. css中的定位属性position(转)

    css中的定位属性position   同样的也是上课的时候发现学生难以理解的一些问题拿出来记录一下,希望帮助初学者. 在css中定位属性position的运用在页面中是很常用的,特别是一些结合js来 ...

  9. CSS中background的用法

    CSS中  background 是一个很基本的而且比较常用的样式 background : background-color || background-image || background-re ...

  10. CSS中的display属性

    CSS中的display属性 display:block是可以把非块级元素强制转换为块级元素显示,如内嵌元素span,原来不支持设置宽高,宽度是由内容撑开的,几个span元素是在同一行内的,如果给sp ...

随机推荐

  1. 七牛直播云-m3u8格式直播

    直播架构 业务服务器:负责协调直播类应用的业务逻辑 创建直播房间 返回直播房间播放地址列表 关闭直播房间 LiveNet 实时流网络:负责流媒体的分发.直播流的创建.查询等相关操作 采集端:负责采集和 ...

  2. Linux之网络文件共享服务(NFS)

    概念: NFS:Network File System 网络文件系统,基于内核的文件系统.Sun公司开发,通过使用NFS,用户和程序可以像访问本地文件一样访问远端系统上的文件,基于RPC(Remote ...

  3. python之cookbook-day04

    第一章:数据结构和算法 1.4 查找最大或最小的N个元素 问题: 怎样从一个集合中获得最大或者最小的 N 个元素列表? 解决方案: heapq 模块有两个函数:nlargest() 和 nsmalle ...

  4. hdu 5176 The Experience of Love

    The Experience of Love  Accepts: 11  Submissions: 108  Time Limit: 4000/2000 MS (Java/Others)  Memor ...

  5. PAT 1108 Finding Average

    The basic task is simple: given N real numbers, you are supposed to calculate their average. But wha ...

  6. Cookie的Python爬虫应用

    Cookie的Python爬虫应用 目录 Cookie是什么 Cookie的作用 Cookie的内容 domain属性 path属性 expires/Max-Age属性 Cookie的爬虫应用 Coo ...

  7. 【codeforces 515B】Drazil and His Happy Friends

    [题目链接]:http://codeforces.com/contest/515/problem/B [题意] 第i天选择第i%n个男生,第i%m个女生,让他们一起去吃饭; 只要这一对中有一个人是开心 ...

  8. ZOJ 3233 Lucky Number

    Lucky Number Time Limit: 5000ms Memory Limit: 32768KB This problem will be judged on ZJU. Original I ...

  9. TLE - Time Limit Exceeded

    TLE - Time Limit Exceeded no tags  Given integers N (1 ≤ N ≤ 50) and M (1 ≤ M ≤ 15), compute the num ...

  10. C++ premier 中文版 学习笔记(第五章 表达式)

    解应用和自增组合使用的理解 由于后自增操作的优先级高于解引用操作,因此 *iter++ 等效于*(iter++).子表达式 iter++ 使 iter 加 1,然后返回 iter 原值的副本作为该表达 ...