search
HomeWeb Front-endCSS TutorialHow to distinguish background-clip and background-origin in css3? (code example)

This chapter will introduce to you how to distinguish background-clip and background-origin in CSS3? (code example). It has certain reference value. Friends in need can refer to it. I hope it will be helpful to you.

In CSS3, background-clip and background-origin have roughly the same functions, but there are some subtle differences.

1. Background-clip attribute

background-clip: Specifies the drawing area of ​​the background. When the background is a pure color and a picture, its display method is different. Same. It has 3 attributes: border-box, padding-box, content-box.

1. border-box: The background is drawn from the border, but when the background is a picture, it is drawn on the left and top There is no picture drawn, but there is one below and on the right;

Code:

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<style>
			div {
			  width:433px;
			  height:200px;
			  padding:50px;
			  background-color: red;
			  background-image:url(&#39;8.jpg&#39;);
			  background-repeat:no-repeat;
			  -webkit-background-clip:border-box;
			  border:10px dashed  #92b901;
			}
		</style>
	</head>

	<body>
		<div>
			这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。
		</div>
	</body>

</html>

Rendering:

How to distinguish background-clip and background-origin in css3? (code example)

##2. padding- box: The background is drawn inside the border (excluding the border);

3. content-box: The background is drawn from the content part;

2. Background-origin attribute

background-origin: Specifies the positioning area of ​​the background image. Its attributes also include border-box, padding-box, and content-box. However, please note that its description is "background image", that is It is said that it can only perform style operations on the background. It is equivalent to positon, which stipulates the area where the picture starts to be drawn. In other words, it is only equivalent to stipulating where the upper left corner of the picture starts, and it is not responsible for the rest;

<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<style>
			div {
				width: 500px;
				height: 300px;
				/*padding: 50px;*/
				background-color: red;
				background-image: url(&#39;8.jpg&#39;);
				background-repeat: no-repeat;
				-webkit-background-origin: content-box;
				background-size: 500px 380px;
				border: 10px dashed #92b901;
			}
		</style>
	</head>

	<body>

		<div>
			这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。 这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。这是文本。
		</div>

	</body>

</html>

Rendering:

How to distinguish background-clip and background-origin in css3? (code example)

background-origin: When drawing a picture, you can start from the border, but some content may be covered by the border. , as shown in the second picture above

The above is the detailed content of How to distinguish background-clip and background-origin in css3? (code example). For more information, please follow other related articles on the PHP Chinese website!

Statement
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
How We Tagged Google Fonts and Created goofonts.comHow We Tagged Google Fonts and Created goofonts.comApr 12, 2025 pm 12:02 PM

GooFonts is a side project signed by a developer-wife and a designer-husband, both of them big fans of typography. We’ve been tagging Google

Timeless Web Dev ArticlesTimeless Web Dev ArticlesApr 12, 2025 am 11:44 AM

Pavithra Kodmad asked people for recommendations on what they thought were some of the most timeless articles about web development that have changed their

The Deal with the Section ElementThe Deal with the Section ElementApr 12, 2025 am 11:39 AM

Two articles published the exact same day:

Practice GraphQL Queries With the State of JavaScript APIPractice GraphQL Queries With the State of JavaScript APIApr 12, 2025 am 11:33 AM

Learning how to build GraphQL APIs can be quite challenging. But you can learn how to use GraphQL APIs in 10 minutes! And it so happens I've got the perfect

Component-Level CMSsComponent-Level CMSsApr 12, 2025 am 11:09 AM

When a component lives in an environment where the data queries populating it live nearby, there is a pretty direct line between the visual component and the

Set Type on a Circle... with offset-pathSet Type on a Circle... with offset-pathApr 12, 2025 am 11:00 AM

Here's some legit CSS trickery from yuanchuan. There is this CSS property offset-path. Once upon a time, it was called motion-path and then it was renamed. I

What does 'revert' do in CSS?What does 'revert' do in CSS?Apr 12, 2025 am 10:59 AM

Miriam Suzanne explains in a Mozilla Developer video on the subject.

The Modern LoversThe Modern LoversApr 12, 2025 am 10:58 AM

I love stuff like this.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SublimeText3 Linux new version

SublimeText3 Linux new version

SublimeText3 Linux latest version