css:实现斑马条纹背景

效果

在这里插入图片描述

代码

<!DOCTYPE html>
<html>
 
	<head>
		<meta charset="UTF-8">
		<title></title>
		<style>
			.container {
				display: flex;
				flex-wrap: wrap;
				justify-content: space-around;
				align-content: space-around;
				width: 1000px;
				height: 900px;
			}
			
			.bg {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 300px;
				height: 200px;
				color: white;
				font-size: 36px;
			}
			
			/*渐变*/
			.bg-first {
				/**
				 * 0-20%为#cc95c0,20%-80%为#cc95c0到#7aa1d2的渐变,80%-100%为#7aa1d2
				 */
				background: linear-gradient(#cc95c0 20%, #7aa1d2 80%);
			}
			
			/*分割*/
			.bg-second {
				/**
				 * 0-50%为#cc95c0,50%-100%为#7aa1d2
				 */
				background: linear-gradient(#cc95c0 50%, #7aa1d2 50%);
			}
			
			/*斑马条纹*/
			.bg-third {
				background: linear-gradient(#cc95c0 50%, #dbd4b4 50%);
				background-size: 100% 40px;
			}
			
			/*三色斑马条纹*/
			.bg-fourth {
				/**
				 * 100% ÷ 3 = 33.3%
				 */
				background: linear-gradient(#cc95c0 33.3%, #dbd4b4 0, #dbd4b4 66.6%, #7aa1d2 0);
				background-size: 100% 40px;
			}
			
			/*竖向双色斑马条纹*/
			.bg-fifth {
				background: linear-gradient(to right, #cc95c0 50%, #dbd4b4 0);
				background-size: 40px 100%;
			}
			
			/*竖向三色斑马条纹*/
			.bg-sixth {
				/**
				 * 100% ÷ 3 = 33.3%
				 */
				background: linear-gradient(to right, #cc95c0 33.3%, #dbd4b4 0, #dbd4b4 66.6%, #7aa1d2 0);
				background-size: 40px 100%;
			}
			
			/*斜向双色斑马条纹*/
			.bg-seventh {
				/**
				 * 50% ÷ 2 = 25%
				 */
				background: linear-gradient(45deg, #cc95c0 25%, #dbd4b4 0, #dbd4b4 50%, #cc95c0 0, #cc95c0 75%, #dbd4b4 0);
				background-size: 40px 40px;
			}
			
			/*斜向三色斑马条纹*/
			.bg-eighth {
				/**
				 * 50% ÷ 3 = 16.66%
				 */
				background: linear-gradient( 45deg, #cc95c0 0, #cc95c0 16.66%, #dbd4b4 16.66%, #dbd4b4 33.33%, #7aa1d2 33.33%, #7aa1d2 50%, #cc95c0 50%, #cc95c0 66.66%, #dbd4b4 66.66%, #dbd4b4 83.33%, #7aa1d2 83.33%, #7aa1d2);
				background-size: 40px 40px;
			}
			
			/*repeating-linear-gradient虚化斑马条纹*/
			.bg-ninth {
				background: #cc95c0;
				background-image: repeating-linear-gradient(45deg, hsla(0, 0%, 100%, 0.1), hsla(0, 0%, 100%, 0.1) 15px, transparent 0, transparent 30px);
			}
			
			/*repeating-linear-gradient斜向双色条纹*/
			.bg-tenth {
				background: repeating-linear-gradient(45deg, #cc95c0, #cc95c0 15px, #dbd4b4 0, #dbd4b4 30px);
			}
			
			/*鳞片式三角条纹*/
			.bg-eleventh {
				background: linear-gradient(45deg, #cc95c0 50%, #dbd4b4 0);
				background-size: 40px 40px;
			}
			
			/*十字格条纹*/
			.bg-twelveth {
				background-image: linear-gradient(0deg, rgba(200, 0, 0, .5) 50%, transparent 50%), linear-gradient(90deg, rgba(200, 0, 0, .5) 50%, transparent 50%);
				background-size: 40px 40px;
			}
		</style>
	</head>
 
	<body>
		<div class="container">
			<div class="bg bg-first">示例一</div>
			<div class="bg bg-second">示例二</div>
			<div class="bg bg-third">示例三</div>
			<div class="bg bg-fourth">示例四</div>
			<div class="bg bg-fifth">示例五</div>
			<div class="bg bg-sixth">示例六</div>
			<div class="bg bg-seventh">示例七</div>
			<div class="bg bg-eighth">示例八</div>
			<div class="bg bg-ninth">示例九</div>
			<div class="bg bg-tenth">示例十</div>
			<div class="bg bg-eleventh">示例十一</div>
			<div class="bg bg-twelveth">示例十二</div>
		</div>
	</body>
 
</html>

转载地址

https://blog.csdn.net/i_dont_know_a/article/details/88695201

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值