CSS background-repeat 属性 | CSS 背景 | CSS教程

返回到:CSS 背景 | CSS教程

标签定义及使用说明

设置如何平铺对象的 background-image 属性。

默认情况下,重复background-image的垂直和水平方向。

默认值:repeat
继承:no
版本:CSS1
JavaScript 语法:object object.style.backgroundRepeat=”repeat-y”

浏览器支持

表格中的数字表示支持该属性的第一个浏览器版本号。

紧跟在 -webkit-, -ms- 或 -moz- 前的数字为支持该前缀属性的第一个浏览器版本号。<

属性谷歌IE火狐苹果opera
background-repeat1.04.01.01.03.5

IE8以及更早版本的浏览器不支持多个背景图像在一个元素。

注意 IE7 和更早的版本不支持 “inherit(继承)”的值。 IE8 需要定义 !DOCTYPE。 IE9 支持 “inherit(继承)”。

提示和注释

提示: background-position 属性设置背景图像位置。如果指定的位置是没有任何背景,图像总是放在元素的左上角。

属性值

说明
repeat背景图像将向垂直和水平方向重复。这是默认
repeat-x只有水平位置会重复背景图像
repeat-y只有垂直位置会重复背景图像
no-repeatbackground-image 不会重复
inherit指定 background-repeat 属性设置应该从父元素继承

实例

1、只有垂直方向重复 background-image。

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>Web176教程(web176.com)</title> 
<style>
body
{
	background-image:url('/wp-content/uploads/2022/02/CSS.jpg');
	background-repeat:repeat-y;
}
</style>
</head>

<body>
<p>repeat-y 设置只有垂直方向重复 background-image</p>
</body>
</html>

2、在垂直和水平方向重复背景图像。

<!DOCTYPE html>
<html>
<head>
	<title>Web176教程(web176.com)</title> 
<style>
body
{
background-image:url('/wp-content/uploads/2022/02/CSS.jpg');
}
</style>
</head>

<body>
<p>默认情况下,在垂直和水平方向重复背景图像。</p>
</body>
</html>

3、重复背景图像仅水平方向。

<!DOCTYPE html>
<html>
<head>
	<title>Web176教程(web176.com)</title> 
<style>
body
{
background-image:url('/wp-content/uploads/2022/02/CSS.jpg');
background-repeat:repeat-x;
}
</style>
</head>

<body>
<p>repeat-x 设置只有水平方向重复 background-image。</p>
</body>
</html>

4、显示一个背景图片没有重复只有一次。

<!DOCTYPE html>
<html>
<head>
	<title>Web176教程(web176.com)</title> 
<style>
body
{
background-image:url('/wp-content/uploads/2022/02/CSS.jpg');
background-repeat:no-repeat;
}
</style>
</head>

<body>
<p>no-repeat 设置显示一个背景图片没有重复只有一次。</p>
</body>
</html>

作者:terry,如若转载,请注明出处:https://www.web176.com/cssprop/5789.html

(0)
打赏 支付宝 支付宝 微信 微信
terryterry
上一篇 2022年4月22日 下午5:21
下一篇 2022年4月22日 下午5:32

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注