温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

background-repeat属性的用法

发布时间:2020-07-08 14:36:26 来源:亿速云 阅读:520 作者:Leah 栏目:web开发

这篇文章将为大家详细讲解有关background-repeat属性的用法,文章内容质量较高,因此小编分享给大家做个参考,希望大家阅读完这篇文章后对相关知识有一定的了解。

CSS的background-repeat属性是用来设置背景图像如何平铺的。background-repeat:repeat-x表示只有水平位置会重复背景图像;background-repeat:repeat-y表示只有垂直位置会重复背景图像。

background-repeat属性的用法

CSS  background-repeat属性

作用:设置是否及如何重复背景图像。

基本语法:

background-repeat:repeat|repeat-x|repeat-y|no-repeat;

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

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

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

no-repeat:设置背景图片不会重复。

说明:background-repeat 属性定义了图像的平铺模式。从原图像开始重复,原图像由 background-image 定义,并根据 background-position 的值放置。

CSS  background-repeat属性的使用示例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"> 
<title>菜鸟教程(runoob.com)</title>
<style>
.demo1{
	width: 400px;
	height: 150px;
	border: 1px solid red;
	background-image:url('https://img.php.cn/upload/article/000/000/024/5c6a4428ea867709.png');
    background-repeat:repeat;
}
.demo2{
	width: 400px;
	height: 100px;
	border: 1px solid red;
	background-image:url('https://img.php.cn/upload/article/000/000/024/5c6a4428ea867709.png');
    background-repeat:no-repeat;
}
.demo3{
	width: 400px;
	height: 150px;
	border: 1px solid red;
	background-image:url('https://img.php.cn/upload/article/000/000/024/5c6a4428ea867709.png');
    background-repeat:repeat-x;
}
.demo4{
	width: 400px;
	height: 400px;
	border: 1px solid red;
	background-image:url('https://img.php.cn/upload/article/000/000/024/5c6a4428ea867709.png');
    background-repeat:repeat-y;
}
</style>
</head>

<body>
<h4>repeat设置背景图片向垂直和水平方向重复</h4>
<div class="demo1"></div>
<h4>no-repeat设置背景图片不重复</h4>
<div class="demo2"></div>
<h4>repeat-x设置背景图片向水平方向重复</h4>
<div class="demo3"></div>
<h4>repeat-y设置背景图片向垂直方向重复</h4>
<div class="demo4"></div>
</body>
</html>

效果图:

background-repeat属性的用法

background-repeat属性的用法

以上就是本篇文章的全部内容,希望能对大家的学习有所帮助。

关于background-repeat属性的用法就分享到这里了,希望以上内容可以对大家有一定的帮助,可以学到更多知识。如果觉得文章不错,可以把它分享出去让更多的人看到。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI