How to use the background-origin attribute

青灯夜游
Release: 2019-01-30 14:17:54
Original
5286 people have browsed it

The background-origin attribute is used to set the positioning area of ​​the background image. It has three values ​​that represent positioning relative to the inner margin box, positioning relative to the border box, and positioning relative to the content box.

How to use the background-origin attribute

CSS3 background-origin attribute

Function: Specifies the positioning area of ​​the background image.

Description: Set or retrieve the reference origin (position) when calculating of the object's background image.

Syntax:

background-origin: padding-box|border-box|content-box;
Copy after login

padding-box: The background image is positioned relative to the padding box.

border-box: The background image is positioned relative to the border box.

content-box: The background image is positioned relative to the content box.

CSS3 background-origin property usage example

<!DOCTYPE html>
<html>
<head>
<style> 
div
{
border:1px solid black;
padding:35px;
background-image:url(&#39;https://img.php.cn/upload/article/000/000/024/5c513adf97e86533.jpg&#39;);
background-repeat:no-repeat;
background-position:left;
}
#div1
{
background-origin:border-box;
}
#div2
{
background-origin:content-box;
}
</style>
</head>
<body>

<p>background-origin:border-box:</p>
<div id="div1">
这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。
</div>

<p>background-origin:content-box:</p>
<div id="div2">
这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。
</div>

</body>
</html>
Copy after login

Rendering:

How to use the background-origin attribute

The above is the entire content of this article, I hope it will be helpful to everyone's study. For more exciting content, you can pay attention to the relevant tutorial columns of the PHP Chinese website! ! !

The above is the detailed content of How to use the background-origin attribute. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template