CSS 基础学习-250 css使用background-origin属性

hrs 提交于 2023/11/13 - 20:48 , 周一

实例代码:


<!doctype html>
<html>
	<head>
		<meta charset="utf-8">
		<style>
			div{
		
				background:url(img/flower.gif);
				background-repeat:no-repeat;
				height:180px;
				padding:35px;
				border:5px solid black;
				width:560px;
			}
			.div-1{
				background-origin:padding-box;
			}
			.div-2{
				background-origin:border-box;
			}
			.div-3{
				background-origin:content-box;
			}
		</style>
	</head>
	<body>
		<h1>background-origin属性</h1>
		<p>未设置background-origin(padding-box 为默认):</p>
		<div class="div-1">
			<h3>Welcome to Shaighai</h3>
			<p>Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!

The city is located on the southern estuary of the Yangtze, with the Huangpu River flowing through it.</p>

	
		</div>
		<p>background-origin:border-box: </p>
		<div class="div-2">
			<h3>Welcome to Shaighai</h3>
			<p>Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!

The city is located on the southern estuary of the Yangtze, with the Huangpu River flowing through it.</p>

	
		</div>
		<p>background-origin:content-box: </p>
		<div class="div-3">
			<h3>Welcome to Shaighai</h3>
			<p>Shanghai is one of the four direct-administered municipalities of the People's Republic of China. Welcome to Shanghai!

The city is located on the southern estuary of the Yangtze, with the Huangpu River flowing through it.</p>

	
		</div>
	</body>
</html>

运行效果:

css-250

 

标签