css如何设置图片平铺方式

本篇内容介绍了“css如何设置图片平铺方式”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

在css中,可利用background-repeat属性设置图片平铺方式,当值为“repeat”时可完全平铺背景,为“repeat-x”时可横向平铺,为“repeat-y”时可纵向平铺,为“no-repeat”时不平铺(图像将仅显示一次)。

css如何设置图片平铺方式

本教程操作环境:windows7系统、CSS3&&HTML5版、Dell G3电脑。

在css中,可利用background-repeat属性设置图片平铺方式。

background-repeat 属性定义了图像的平铺模式,设置是否及如何重复背景图像。

background-repeat属性可以设置四种平铺模式:

1、值为“repeat”时可完全平铺背景

repeat :默认。背景图像将在垂直方向和水平方向重复。

<!DOCTYPE html>
<html>
	<head>
		<style>
			div {
				width: 500px;
				height: 500px;
				border: 2px solid red;
				background-image: url(img/nz.png);
				background-repeat:repeat;
			}
		</style>
	</head>
	<body>
		<div ></div>
	</body>
</html>

css如何设置图片平铺方式

2、值为“repeat-x”时可横向平铺

repeat-x : 只有水平位置会重复背景图像

div {
	width: 500px;
	height: 500px;
	border: 2px solid red;
	background-image: url(img/nz.png);
	background-repeat:repeat-x;
}

css如何设置图片平铺方式

3、值为“repeat-y”时可纵向平铺

repeat-y :只有垂直位置会重复背景图像

div {
	width: 500px;
	height: 500px;
	border: 2px solid red;
	background-image: url(img/nz.png);
	background-repeat:repeat-y;
}

css如何设置图片平铺方式

4、值为“no-repeat”时则不平铺

no-repeat:背景图像将仅显示一次

div {
	width: 500px;
	height: 500px;
	border: 2px solid red;
	background-image: url(img/nz.png);
	background-repeat:no-repeat;
}

css如何设置图片平铺方式

“css如何设置图片平铺方式”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注网站,小编将为大家输出更多高质量的实用文章!